@adsk-sdk/oss v0.0.12
(PREVIEW VERSION) Object Storage Service (OSS) SDK
Oss - JavaScript client for oss The Object Storage Service (OSS) allows your application to download and upload raw files (such as PDF, XLS, DWG, or RVT) that are managed by the Data service.
Simple Quick Start Tutorial
Step 1: Create your sample structure
mkdir sample
cd sample
- Copy content from Sample.js below to above sample folder.
- Copy content from Package.json below to above sample folder.
Step 2: Install the library
Assuming your package.json contains the following as copied in step 1:
{
"dependencies": {
"@adsk-sdk/oss": "^0.0.5",
"@adsk-sdk/auth": "^0.0.2"
}
}
In your sample folder, run
npm install
Step 3: Edit your sample script to include your Forge staging environment client id and secret
Obtain your client id and client secret from https://forge.autodesk.com.
If unfamiliar with this process, follow these steps: 1. Sign in to the Forge staging portal https://forge.autodesk.com 2. If you have not done so previously, create an app by selecting Create Forge App (Traditional Web App). 3. Select your app to get to the App details page. 4. Copy your client id and secret from here.
Update this line in the sample.js with your client id and secret. If user wants to pass authorization token while calling the function, clientId and clientSecret should be empty.
var api = new Oss.OSSApi(ossclient, 'prod', "<Your-ClientID>", "<Your-ClientSecret>");
Run sample.js
node sample.js
Package.json
{
"dependencies": {
"@adsk-sdk/oss": "^0.0.6",
"@adsk-sdk/auth": "0.0.2"
}
}
Sample.js
const Oss = require("@adsk-sdk/oss");
var config = {
circuitBreaker: {
threshold: 11,
interval: 1200,
},
retry: {
maxNumberOfRetries: 7,
backoffDelay: 4000,
backoffPolicy: "exponentialBackoffWithJitter",
},
requestTimeout: 13000,
};
var ossclient = new Oss.OssClient(config);
// If you want to pass an authorization token while calling this method, client ID and clientSecret can be empty.
var api = new Oss.OSSApi(ossclient, 'prod', "<Your-ClientID>", "<Your-ClientSecret>");
// If user is setting client ID and client Secret <authorizationToken> should be empty.
api
.getBuckets({}, '<authorizationToken>')
.then((result) => {
console.log("Result of Get Bucket call: " + JSON.stringify(result));
})
.catch((error) => console.log("Error from Get Bucket call: " + error));
General instructions
Installation
npm
Install this package using the following command:
npm install @adsk-sdk/oss
npm install @adsk-sdk/auth
This installs packages for NodeJS.
Configuring ApiClient
You can use default settings or change following properties of ApiClient
.
1. CircuitBreaker :
Configure the threshold failure count and failure interval of circuit breaker.
Default : Failure Count : 10 Failure interval : 10000 ms
```javascript
const Oss = require('@adsk-sdk/oss');
var config = {
"circuitBreaker": {
"threshold": 11,
"interval": 1200
}
};
var apiClient = new Oss.OssClient(config);
// If user wants to pass authorization token while calling method, clientId and clientSecret should be empty.
var api = new Oss.OSSApi(ossclient, 'prod', "<Your-ClientID>", "<Your-ClientSecret>");
```
Retry : Autodesk resiliency library provides 3 types of retry policies.
* WAIT : Retry after fixed delay interval. * EXPONENTIAL : Retry after exponential delay interval. * JITTER : Retry after exponential delay with jitter interval. User can specify number of retry count and retry policy. ```javascript const Oss = require('@adsk-sdk/oss'); var config = { "retry" : { "maxNumberOfRetries" : 7, "backoffDelay" : 4000, "backoffPolicy" : "exponentialBackoffWithJitter" } }; var apiClient = new Oss.OssClient(config); //If user wants to pass authorization token while calling method, clientId and clientSecret should be empty. var api = new Oss.OSSApi(ossclient, 'prod', "<Your-ClientID>", "<Your-ClientSecret>"); ```
Timeout : Set request timeout.
const Oss = require('@adsk-sdk/oss'); var config = { "requestTimeout" : 13000 }; var apiClient = new Oss.OssClient(config); //If user wants to pass authorization token while calling method, clientId and clientSecret should be empty. var api = new Oss.OSSApi(ossclient, 'prod', "<Your-ClientID>", "<Your-ClientSecret>"); ```
Getting Started with OSS SDK
Please follow the installation instructions and execute the following JS code:
- Default common scenario You start by instantiating the oss api object. Setting credential if you want auth to happen automatically. Then call a specific API as given in the sample below.
var ossclient = new Oss.OssClient(config);
var api = new Oss.OSSApi(ossclient, 'prod', "<Your-ClientID>", "<Your-ClientSecret>");
api
.getBuckets({}, '')
.then((result) => {
console.log("Result of Get Bucket call: " + JSON.stringify(result));
})
.catch((error) => console.log("Error from Get Bucket call: " + error));
ApiClient
configuration
const Oss = require('@adsk-sdk/oss');
var config = {
"retry" : {
"maxNumberOfRetries" : 7,
"backoffDelay" : 4000,
"backoffPolicy" : "exponentialBackoffWithJitter"
},
"circuitBreaker": {
"threshold": 11,
"interval": 1200
},
"requestTimeout" : 13000
};
Documentation for Authorization
Supplying your own access token
In some instance if developers want to use their own authentication mechanism. Then they can supply Bearer token inside the header while passing to API. As show in the sample below.
var ossclient = new Oss.OssClient(config);
var api = new Oss.OSSApi(ossclient, 'prod', '', '');
api
.getBuckets({}, '<AuthorizationToken>')
.then((result) => {
console.log("Result of Get Bucket call: " + JSON.stringify(result));
})
.catch((error) => console.log("Error from Get Bucket call: " + error));
Authorizing automatically
Note that OSS SDK calls can automatically authorize itself if a client id and secrets were to set using setCredentials() call. Like in the sameple below -
var ossclient = new Oss.OssClient(config);
var api = new Oss.OSSApi(ossclient, 'prod', "<Your-ClientID>", "<Your-ClientSecret>");
api
.getBuckets({}, '')
.then((result) => {
console.log("Result of Get Bucket call: " + JSON.stringify(result));
})
.catch((error) => console.log("Error from Get Bucket call: " + error));
OAuth 2.0 application
- Type: OAuth
- Flow: application
- Authorization URL:
- Scopes:
- data:read: The application will be able to read the end user’s data within the Autodesk ecosystem.
- data:write: The application will be able to create, update, and delete data on behalf of the end user within the Autodesk ecosystem.
- data:create: The application will be able to create data on behalf of the end user within the Autodesk ecosystem.
- bucket:create: The application will be able to create an OSS bucket it will own.
- bucket:read: The application will be able to read the metadata and list contents for OSS buckets that it has access to.
- bucket:update: The application will be able to set permissions and entitlements for OSS buckets that it has permission to modify.