Files Management
Using Trillo Workbench APIs, manage folders and files from your application. Trillo provides user and group access control for files and folders. All files/folder operations are available as APIs.

Architecture

The following diagram shows how you can use APIs from your program to manage folders and files. The files are stored in the Google Cloud Storage bucket. Trillo implements folder and folder access control by users and groups. Trillo provides APIs for copying, moving, removing (soft and permanent), accessing old versions, etc. Trilo provides API to obtain a signed URL for uploading and downloading files. A signed URL permits to upload and download files without having to go through the Trillo Workbench thus avoiding extra load on the service.
Folder and FIle Management using Trillo WOrkbench

Trillo File Manager

Trillo File Manager is a standalone product. It is also a part of the Trillo Workbench. It is similar to DropBox or GDrive on the top of the Google Cloud Storage bucket. It has the following features:
  • UI for folder and file management.
    • Create folder hierarchy.
    • Upload one or more files.
    • Move, copy, delete, rename files.
    • Versioning of files.
    • Sharing of files.
    • Download one or more files.
  • SFTP server (including using public/private key-pairs).
  • API for uploading and downloading files from an external client.
See the document Trillo File Manager Documentation for SFTP and user management. Its UI is intuitive.
This document discusses the file upload, download APIs for Trillo File Manager (or you can also refer to them as APIs of Trillo Workbench since it is integrated within it).

APIs Flow

This section describes the concepts of the flow. The following section describes each API in detail.
Trillo uses the GCP Cloud storage bucket for files. But you don't have to worry about GCP configuration, managing its service tokens securely, etc. It is transparently taken care of by the Trillo platform. Instead, you use Trillo restful APIs. Trillo platform handles multiple environments, tenants, users, groups, folders. keeping the bucket content in sync with the database, etc.
Step 1 is to acquire an API access-token (like any other restful API). You may already have acquired access-token previously such as during login.
The following steps vary depending on the upload or download.

Upload Flow

Step 2 call API to retrieve the signed URL for putting the file. The signed URL is used to transfer the file to the GCP bucket directly. The signed URL is hard to guess URL with encrypted security info in the parameter. It is also short-lived and becomes invalid after some time.
Step 3 use the signed URL to upload the file through Multipart/form-data request.
Step 4 save the file object into the database (Trillo platform maintains the cache of content on the file into the database for performance and implementing access control). Trillo platform will eventually, sync the bucket with the database. But the save call ensures that the database is in sync with the content of the bucket.

Download Flow

Step 2 call API to retrieve the signed URL for getting the file.
Step 3 use the signed URL to download the file. For example, you can open the URL in a new or the same browser table using JavaScript call.

Acquire Access Token

Use the following API to get the authentication token. You would normally obtain it during the login if you are using the Trillo platform login. Otherwise, you can obtain it using a service account. Trillo provides an extension (since it is outside OAuth2 flow) to provide an access token on the behalf of the service account that acts on behalf of the user (this assumes that the proxy user is created inside the Trillo platform).
All restful API calls assume the following header. If no other headers are required, the headers section is skipped.
1
'Content-Type':'application/json'
Copied!
End-point:
1
POST /oauth/token
Copied!
Body:
1
{
2
"grant_type" : "password",
3
"username" : "[email protected]",
4
"password" "sdyhf6^@dw"
5
}
Copied!
Response:
1
{
2
"access_token":"MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3",
3
"token_type":"bearer",
4
"expires_in":3600,
5
"refresh_token":"IwOGYzYTlmM2YxOTQ5MGE3YmNmMDFkNTVk",
6
"scope": "comman separated list of roles"
7
}
Copied!

Passing Access Token in All API Calls

Unless specified, all APIs need to be passed access-token in the header as follows:
1
'Authorization':'Bearer + <value of the accss token'
2
'Content-Type':'application/json'
3
4
5
Note space after Bearer.
Copied!

Upload Flow

The following sections describe 3 API calls for the upload flow.

Retrieve Upload Signed URL

The first step of the upload flow is to retrieve a signed URL.
End-point:
1
POST /foldersvc/cloudstorage/folder/retieveSignedUrl
Copied!
Body:
1
{
2
“folderName” : <cloud storage bucket folder>,
3
"subFolder": "<sub folder if any>",
4
“contentType” :<file content type>,
5
“fileName” : “<name of the file to be uploaded>,
6
“method” : “PUT”
7
}
8
9
The parameter “method” : “PUT” above is a parameter to the signed URL.
10
It does not imply HTTP method.
11
12
The "subFolder" parameter is useful when loading a directory recursive.
13
You can also add it to the "folderName".
14
Copied!
Response:
1
{
2
“code” : 200,
3
“data: {
4
“signedUrl” : “value of signed url”
5
}
6
}
Copied!

Upload File Using Signed URL

The next step is to upload the actual file using the signed URL. The AJAX call is shown in the code snippet below.
End-point:
1
PUT <signed url value>
Copied!
Header:
1
'Content-Type': 'multipart/formdata; charset=UTF-8'
2
3
Note this API uses a different content type.
Copied!
Body:
1
{
2
actual file
3
}
Copied!
Response:
1
Returns HTTP code 200 if successful. No body is returned.
Copied!

Save File Object

The last step of the upload flow is to save the file object in the database.
End-point:
1
POST /foldersvc/cloudstorage/folder/retieveSignedUrl
Copied!
Body:
1
{
2
“folderName” : <cloud storage bucket folder>,
3
"subFolder": "<sub folder if any>",
4
“contentType” :<file content type>,
5
“fileName” : “<name of the file to be uploaded>,
6
"provider":"cloudstorage"
7
}
Copied!
Response: It returns the file object created in the database as JSON. An example is shown below.
1
{
2
"fileName":"TrillWorkbench-Database-Tabs.png",
3
"folderName":"/users/test201/Home/tmp",
4
"folderId":84,
5
"className":"",
6
"url":"#cloudstorage",
7
"contentUrl":"#cloudstorage",
8
"title":"TrillWorkbench-Database-Tabs.png",
9
"provider":"cloudstorage",
10
"size":79336,
11
"contentType":"image/png",
12
"_uniqueness_condition_":null,
13
"fileType":"png",
14
"idOfUser":3,
15
"userId":"test201",
16
"firstName":"Test",
17
"lastName":"Test123",
18
"topFolderId":82,
19
"createdAt":1615795228850,
20
"deletedAt":0,
21
"deleted":false,
22
"updatedAt":1615795228850,
23
"versionsCount":0,
24
"id":444
25
}
Copied!

Download Flow

The following sections describe the steps of download flow.

Retrieve Download Signed URL

The first step of the upload flow is to retrieve a signed URL.
End-point:
1
POST /foldersvc/cloudstorage/folder/retieveSignedUrl
Copied!
Body:
1
{
2
“folderName” : <cloud storage bucket folder>,
3
“contentType” :<file content type>,
4
“fileName” : “<name of the file to be downloaded>,
5
"fileId" : "<databse id of the file>",
6
“method” : “GET”
7
}
8
9
The parameter “method” : “GET” above is a parameter to the signed URL.
10
It does not imply HTTP method.
11
12
In the above API you can pass, either "fileId", or "fileName"
13
and "folderName". If "fileId" is passed the the name of the file
14
and folder are retrieved from the database.
Copied!
Response:
1
{
2
“code” : 200,
3
“data: {
4
“signedUrl” : “value of signed url”
5
}
6
}
Copied!