• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Node.js SDK)
  4. Temporary Authentication
  5. Temporarily Authorized Request

Temporarily Authorized Request

You can call ObsClient.createV2SignedUrlSync to create a URL for a temporarily authorized request. The following sample code creates a URL for common operations, including bucket creation, as well as object upload, download, listing, and deletion.

// Import the OBS library.
var ObsClient = require('./lib/obs');

// Create an instance of ObsClient.
var obsClient = new ObsClient({
    access_key_id: '*** Provide your Access Key ***',       
    secret_access_key: '*** Provide your Secret Key ***',       
    server : 'yourdomainname'
});

// Specify the validity period of the URL to 3600 seconds.
let expires = 60 * 60;

// Create a bucket.
let res = obsClient.createV2SignedUrlSync({Method : 'PUT', Bucket : 'bucketname', Expires : expires});
console.log('\t' + res.SignedUrl);

// Upload an object.
res = obsClient.createV2SignedUrlSync({Method : 'PUT', Bucket : 'bucketname', Key : 'objectkey', Expires : expires, Headers : {'Content-Type' : 'text/plain'}});
console.log('\t' + res.SignedUrl);

// Download an object.
res = obsClient.createV2SignedUrlSync({Method : 'GET', Bucket : 'bucketname', Key : 'objectkey', Expires : expires});
console.log('\t' + res.SignedUrl);

// List objects.
res = obsClient.createV2SignedUrlSync({Method : 'GET', Bucket : 'bucketname', Expires : expires});
console.log('\t' + res.SignedUrl);

// Delete an object.
res = obsClient.createV2SignedUrlSync({Method : 'DELETE', Bucket : 'bucketname', Expires : expires});
console.log('\t' + res.SignedUrl);
NOTE:
  • Use the Method parameter to specify the HTTP request method, the Expires parameter to specify the validity period of the URL, the Headers parameter to specify the request headers, the SpecialParam parameter to specify the special operator, and the QueryParams parameter to specify the request parameters.