Top Menu

Jump to content
Home
    Modules
      • Projects
      • Activity
      • Work packages
      • Gantt charts
      • Calendars
      • Team planners
      • Boards
      • News
    • Getting started
    • Introduction video
      Welcome to OpenProject Community
      Get a quick overview of project management and team collaboration with OpenProject. You can restart this video from the help menu.

    • Help and support
    • Upgrade to Enterprise edition
    • User guides
    • Videos
    • Shortcuts
    • Community forum
    • Enterprise support

    • Additional resources
    • Data privacy and security policy
    • Digital accessibility (DE)
    • OpenProject website
    • Security alerts / Newsletter
    • OpenProject blog
    • Release notes
    • Report a bug
    • Development roadmap
    • Add and edit translations
    • API documentation
  • Sign in
      Forgot your password?

      or sign in with your existing account

      Google

Side Menu

  • Overview
  • Activity
    Activity
  • Roadmap
  • Work packages
    Work packages
  • Gantt charts
    Gantt charts
  • Calendars
    Calendars
  • Team planners
    Team planners
  • Boards
    Boards
  • News
  • Forums

Content

Updated by Wieland Lindenthal over 3 years ago

# This specification is "Work in progress" and is not yet finished.

## File link resources

`FileLink` resources in OpenProject describe links between resources in OpenProject (first work packages, maybe in the future wiki pages, etc.) and their representation in a file store, i.e. a file in Nextcloud or in a Google Drive.

A `FileLink` consists of roughly three types of attributes

* first class citizens such as
* the link's ID (not the file's ID)
* the storage ID within OpenProject (That becomes handy once we want to allow for multiple storages)
* origin data which are attributes of the linked file
* the files ID in external file storage, such as Nextcloud's `fileId`.
* the file name
* the file's mime type
* the name of the files author who created the file
* the name of the person who last updated the file
* links to other, mostly OpenProject resources
* The user/author who created the link
* The container to which the file is linked to, i.e. a certain work package. In future it could be also something else such as wiki pages etc.
* The path for deletion
* Links for downloading the file
* One that is the download location from the origin
* Another that is redirecting to the one above but is relative to OpenProject's root (in case the one above changes for whatever reason)
* A link for opening the file in the origin's web app, i.e. open the a .docx in the Nextcloud online editor
* Maybe we even need a link to show the file in the origin's web app's file structure

## GET all file links to work packages of project a project from a certain file store

Example: _"Get all file links linking to work packages in project 5 that are stored in file store 1"_

For readability reasons we chose to show the URL params not URL encoded in this example. The params must be URL encoded first if you want to use them in a real example.

`GET /api/v3/file_links?filters=[{"resource_type":{"operator":"=","values":["WorkPackage"]}},{"project_id":{"operator":"=","values":["5"]}},{"file_store":{"operator":"=","values":["1"]}}]`

This will return a collection of file reference resources.

```json
{
"_type" : "collection",
"count" : 2,
"total" : 2,
"_embedded" : {
"elements" : [
{
"id" : 1,
"storageType" : "nextcloud",
"storageId" : 1,
"createdAt" : "2021-12-20T14:01:45Z",
"updatedAt" : 2021-12-20T15:12:01Z",
"originData" : {
"id" : 5502
"createdAt" : "2021-12-20T13:37:45Z",
"lastModifiedAt" : "2021-12-20T14:27:01Z",
"authorName" : "Manuel Müller",
"lastModifiedByName" : "Christina Bolz",
"fileName" : "picture_1.png",
"mimeType" : "image/png",
},
"_links" : {
"self" : {
"href" : "/api/v3/file_links/1",
"title" : "picture_1.png"
},
"downloadLocation" : "https://mynextcloud.com/..."
"staticDownloadLocation" : "/api/v3/file_links/1/download",
"originOpen" "origin" : "https://mynextcloud.com/index.php/apps/files/?fileid=5502",
"originShowLocation" : "https://mynextcloud.com/index.php/apps/files/?fileid=5502",
"author" : {
"href" : "/api/v3/users/3145",
"title" : "Richard Wolf",
},
"delete" : {
"href" : "/api/v3/file_links/1",
"method" : "delete"
},
"container" : {
"href" : "/api/v3/work_packages/22",
"title" : "Awesome work package with file references"
}

},
"_type" : "FileLink"
},
{
...another file link
}
]
}

},
```

## GET work packages that are related to file's origin ID file link

To query all work packages that are linked to a file you need to apply the filter `origin_id` and `file_store` `originId` to the `work_packages` API endpoint.  This filter allows only one operator `=` and multiple IDs as values, for example in case of a Nextcloud storage the IDs are Nextclouds `fileid`s.

Example: _"Get all work packages that are linked to two certain files with their original IDs being 1234 and 1235 and the storage ID 1."_ 1235."_

Attention: For readability reasons we chose to show the URL params not URL encoded in this example. The params must be URL encoded first if you want to use them in a real example.

`GET /api/v3/work_packages?filters=[{"origin_id":{"operator":"=","values":["1234","1235"]}},{"file_store":{"operator":"=","values":["1"]}}]` /api/v3/work_packages?filters=[{"originId":{"operator":"=","values":["1234","1235"]}}]`

This will return a collection of work package resources.

## **GET file links that are related to a work package**

For displaying all links to all files next to a work package, for example in a "Nextcloud" tab of a work package, we need to be able to query all file links linking to a work package.

Example: _"Get me all files that are linked to work package 1."_

For readability reasons we chose to show the URL params not URL encoded in this example. The params must be URL encoded first if you want to use them in a real example.

`GET /api/v3/file_links?filters=[{"container_type":{"operator":"=","values":["WorkPackage"]}},{"container_id":{"operator":"=","values":["1"]}}]`

## CREATE a file link

To create a link between a file and a work package we need make a POST request, containing the storage ID, the original file ID (i.e. Nextcloud's `fileid`) and the work package ID.

Example: "Create a link between work package 2 and file 1234 in storage 1."

`POST /api/v3/file_links`

with payload

```json
{
"storageId" : 1,
"originId" : 1234,
"workPackageId" : 2
}
```

The return value will be the created `FileLink` resource as described above.

## DELETE a file link

Example: _"Delete file link with ID 1."_

`DELETE /api/v3/file_links/1`

## Nice to have: UPDATE origin data of a file link

It might be necessary to offer a way to update the origin data of a file link as files attributes could change at its origin, such as its file name, mime type, last modified timestamp and the name of the person that last modified the file. However, I am not sure if we will really need it in the first version.
Loading...