TrimbleCloud.DataOcean3
Data Ocean SDK for JavaScript.
Getting Started
Installation
This package is available in Trimble Artifactory NPM registry. It can be installed with the following command:
npm install @trimblecloudplatform/trimblecloud.dataocean3
Data Ocean Endpoints
| Environment | Base URL Endpoint |
|---|---|
| Stage | https://cloud.stage.api.trimblecloud.com/dataocean/api/3.0 |
| Production | https://cloud.api.trimble.com/dataocean/api/3.0 |
Usage
Create the client
The client can be configured with the following options:
var StorageClient = require('@trimblecloudplatform/trimblecloud.dataocean3');var client = new StorageClient(new BearerTokenHttpClientProvider(tokenProvider, 'https://cloud.stage.api.trimblecloud.com/dataocean/api/3.0'));To upload a file, include an instance of SimpleHttpClientProvider as a parameter.
const SimpleHttpClientProvider = require('@trimble-oss/trimble-id/SimpleHttpClientProvider')var client = new StorageClient(new BearerTokenHttpClientProvider(tokenProvider, 'https://cloud.stage.api.trimblecloud.com/dataocean/api/3.0'), new SimpleHttpClientProvider());Get Started with Directories
Create directory
The following example shows how to create a directory with the specified path and access control list (ACL). Please refer API reference for more details.
client.Directories.Create({ "path": "/path/to/directory", "acl": { "trn:tid:application:f85bc802-5481-4581-b972-c4652d595ec7": "w", "trn:tid:user:6529d0b3-5856-41ab-88b3-86f7955cddf1": "r", "trn:tid:user:7529d0b3-5856-41ab-88b3-86f7955cddf1;trn:profilex:group:all_applications": "r", "trn:tid:device:8529d0b3-5856-41ab-88b3-86f7955cddf1;trn:tid:application:f85bc802-5481-4581-b972-c4652d595ec7": "d", "trn:profilex:group:all_devices;trn:tid:application:f85bc802-5481-4581-b972-c4652d595ec7": "w" } }) .then((directory) => {}) .catch(() => {});Delete directory
The following example shows how to delete a directory by id.
client.Directories.Delete("directory_id") .then(() => {}) .catch(() => {});Delete directory by path
The following example shows how to delete a directory by path.
client.Directories.DeleteByPath("/path/to/directory") .then(() => {}) .catch(() => {});Get directory
The following example shows how to get a directory by id.
client.Directories.Read("directory_id") .then((directory) => {}) .catch(() => {});Get directory by path
The following example shows how to get a directory by path.
client.Directories.ReadByPath("/path/to/directory") .then((directory) => {}) .catch(() => {});List directories in a directory
The following example shows how to list directories in a directory by id.
client.Directories.GetDirectoriesList("directory_id").GetItems(). .then((directories) => {}) .catch(() => {});List directories in a directory by path
The following example shows how to list directories in a directory by path.
client.Directories.GetDirectoriesListByPath("/path/to/directory").GetItems() .then((directories) => {}) .catch(() => {});List files in a directory
The following example shows how to list files in a directory by id.
client.Directories.GetFilesList("directory_id").GetItems() .then((files) => {}) .catch(() => {});List files in a directory by path
The following example shows how to list files in a directory by path.
client.Directories.GetFilesListByPath("/path/to/directory").GetItems() .then((files) => {}) .catch(() => {});Get Started with Files
Create a file
The following example shows how to create a file with the specified path and access control list (ACL). Please refer API reference for more details.
client.Files.Create({ "path": "/path/to/file.jpeg", "restricted_access": true, "regions": [ "us1" ], "fileset": false, "path_template": "{country}/{city}.kml", "expires_at": null, "multipart": false, "response_headers": { "response-content-type": "image/jpeg", "response-content-disposition": "inline", "response-cache-control": "max-age=3000" }, "metadata": { "author": "Brandon Skari", "language": "Suomi" }, "acl": { "trn:tid:application:f85bc802-5481-4581-b972-c4652d595ec7": "w", "trn:tid:user:6529d0b3-5856-41ab-88b3-86f7955cddf1": "r", "trn:tid:user:7529d0b3-5856-41ab-88b3-86f7955cddf1;trn:profilex:group:all_applications": "r", "trn:tid:device:8529d0b3-5856-41ab-88b3-86f7955cddf1;trn:tid:application:f85bc802-5481-4581-b972-c4652d595ec7": "d", "trn:profilex:group:all_devices;trn:tid:application:f85bc802-5481-4581-b972-c4652d595ec7": "w" }, "master_id": "b0cb3ba7-18e6-442e-b1d9-25d5fd3b41de" }, "response": { "brief": false }) .then((file) => {}) .catch(() => {});Delete a file
The following example shows how to delete a file by id.
client.Files.Delete("file_id") .then(() => {}) .catch(() => {});Delete a file by path
The following example shows how to delete a file by path.
client.Files.DeleteByPath("/path/to/file.txt") .then(() => {}) .catch(() => {});Get a file
The following example shows how to get a file by id.
client.Files.Read("file_id") .then((file) => {}) .catch(() => {});Get a file by path
The following example shows how to get a file by path.
client.Files.ReadByPath("/path/to/file.txt") .then((file) => {}) .catch(() => {});List file versions
The following example shows how to list file versions by id.
client.Files.GetVersionList("file_id").GetItems() .then((versions) => {}) .catch(() => {});List file versions by path
The following example shows how to list file versions by path.
client.Files.GetVersionListByPath("/path/to/file.txt").GetItems() .then((versions) => {}) .catch(() => {});Update a file
The following example shows how to update a file by id.
client.Files.Update("file_id", { "path": "/path/to/file.txt", "expires_at": null, "restricted_access": true, "response_headers": { "+": { "response-content-type": "image/jpeg", "response-content-disposition": "inline" }, "-": [ "response-cache-control" ] }, "metadata": { "language": "Suomi" }, "acl": { "trn:tid:application:f85bc802-5481-4581-b972-c4652d595ec7": "w", "trn:tid:user:6529d0b3-5856-41ab-88b3-86f7955cddf1": "r", "trn:tid:user:7529d0b3-5856-41ab-88b3-86f7955cddf1;trn:profilex:group:all_applications": "r", "trn:tid:device:8529d0b3-5856-41ab-88b3-86f7955cddf1;trn:tid:application:f85bc802-5481-4581-b972-c4652d595ec7": "d", "trn:profilex:group:all_devices;trn:tid:application:f85bc802-5481-4581-b972-c4652d595ec7": "w" } }) .then((file) => {}) .catch(() => {});Update a file by path
The following example shows how to update a file by path.
client.Files.UpdateByPath("/path/to/file.txt", { "path": "/path/to/file.txt", "expires_at": null, "restricted_access": true, "response_headers": { "+": { "response-content-type": "image/jpeg", "response-content-disposition": "inline" }, "-": [ "response-cache-control" ] }, "metadata": { "language": "Suomi" }, "acl": { "trn:tid:application:f85bc802-5481-4581-b972-c4652d595ec7": "w", "trn:tid:user:6529d0b3-5856-41ab-88b3-86f7955cddf1": "r", "trn:tid:user:7529d0b3-5856-41ab-88b3-86f7955cddf1;trn:profilex:group:all_applications": "r", "trn:tid:device:8529d0b3-5856-41ab-88b3-86f7955cddf1;trn:tid:application:f85bc802-5481-4581-b972-c4652d595ec7": "d", "trn:profilex:group:all_devices;trn:tid:application:f85bc802-5481-4581-b972-c4652d595ec7": "w" } }) .then((file) => {}) .catch(() => {});Copy a file
The following example shows how to copy a file by id.
client.Files.Copy("file_id", { "path": "/path/to/file.txt", "expires_at": null, "restricted_access": true, "response_headers": { "+": { "response-content-type": "image/jpeg", "response-content-disposition": "inline" }, "-": [ "response-cache-control" ] }, "metadata": { "language": "Suomi" }, "acl": { "trn:tid:application:f85bc802-5481-4581-b972-c4652d595ec7": "w", "trn:tid:user:6529d0b3-5856-41ab-88b3-86f7955cddf1": "r", "trn:tid:user:7529d0b3-5856-41ab-88b3-86f7955cddf1;trn:profilex:group:all_applications": "r", "trn:tid:device:8529d0b3-5856-41ab-88b3-86f7955cddf1;trn:tid:application:f85bc802-5481-4581-b972-c4652d595ec7": "d", "trn:profilex:group:all_devices;trn:tid:application:f85bc802-5481-4581-b972-c4652d595ec7": "w" } }) .then((file) => {}) .catch(() => {});Copy a file by path
The following example shows how to copy a file by path.
client.Files.CopyByPath("/path/to/file.txt", { "path": "/path/to/file.txt", "expires_at": null, "restricted_access": true, "response_headers": { "+": { "response-content-type": "image/jpeg", "response-content-disposition": "inline" }, "-": [ "response-cache-control" ] }, "metadata": { "language": "Suomi" }, "acl": { "trn:tid:application:f85bc802-5481-4581-b972-c4652d595ec7": "w", "trn:tid:user:6529d0b3-5856-41ab-88b3-86f7955cddf1": "r", "trn:tid:user:7529d0b3-5856-41ab-88b3-86f7955cddf1;trn:profilex:group:all_applications": "r", "trn:tid:device:8529d0b3-5856-41ab-88b3-86f7955cddf1;trn:tid:application:f85bc802-5481-4581-b972-c4652d595ec7": "d", "trn:profilex:group:all_devices;trn:tid:application:f85bc802-5481-4581-b972-c4652d595ec7": "w" } }) .then((file) => {}) .catch(() => {});Upload a file
The following example shows how to upload a file by id.
client.Files.Upload("file_id", "file_version", file_content)Upload a file by path
The following example shows how to upload a file by path.
client.Files.UploadByPath("/path/to/file.txt", "file_version", file_content)List files
The following example shows how to list files.
client.Files.ListFiles() .then((files) => {}) .catch(() => {});Events
File events
The following example shows how to subscribe to file events. Below is the list of supported events.
- upload_complete
- upload_progress
- upload_failed
- file_created
client.Events.Subscribe("upload_complete", (event) => {});client.Events.Subscribe("upload_progress", (event) => {});client.Events.Subscribe("upload_failed", (event) => {});client.Events.Subscribe("file_created", (event) => {});....