Updated on 2023-03-16 GMT+08:00

Creating a Signed URL

API Description

You can use this API to generate a URL whose Query parameter is carried with authentication information, by specifying the AK and SK, HTTP method, and request parameter. You can use a signed URL to perform specific operations on OBS.

Method Definition

ObsClient.createSignedUrlSync

Request Parameter

Field

Type

Optional or Mandatory

Description

Method

String

Mandatory

HTTP method. Possible values are:

  • GET
  • POST
  • PUT
  • DELETE
  • HEAD

Bucket

String

Optional

Bucket name

Key

String

Optional

Object name

SpecialParam

String

Optional

Special operator, which indicates the sub-resource to be operated. Possible values are:

  • versions
  • uploads
  • location
  • storageinfo
  • quota
  • storagePolicy
  • acl
  • append
  • logging
  • policy
  • lifecycle
  • website
  • versioning
  • cors
  • notification
  • tagging
  • delete
  • restore

Expires

Number

Optional

Expiration time of the signed URL, in seconds. The default value is 300.

Headers

Object

Optional

Headers in the request

QueryParams

Object

Optional

Query parameters in the request

Returned Result

Field

Type

Description

SignedUrl

String

Signed URL

ActualSignedRequestHeaders

Object

Actual headers in the request initiated by using the signed URL

Sample Code

// Generate a signed URL for uploading an object.
var putObjectResult = obsClient.createSignedUrlSync({Method : 'PUT', Bucket : 'bucketname', Key : 'objectkey', Headers : {'Content-Type' : 'text/plain'}});
console.log('SignedUrl-->' + putObjectResult['SignedUrl']);
console.log('ActualSignedRequestHeaders-->' + JSON.stringify(putObjectResult['ActualSignedRequestHeaders']));

// Generate a signed URL for setting an object ACL.
var setObjectAclResult = obsClient.createSignedUrlSync({Method : 'PUT', Bucket : 'bucketname', Key : 'objectkey', SpecialParam: 'acl', Headers: {'x-amz-acl' : 'public-read'}});
console.log('SignedUrl-->' + setObjectAclResult['SignedUrl']);
console.log('ActualSignedRequestHeaders-->' + JSON.stringify(setObjectAclResult['ActualSignedRequestHeaders']));

// Generate a signed URL for downloading an object.
var getObjectResult = obsClient.createSignedUrlSync({Method : 'GET', Bucket : 'bucketname', Key : 'objectkey'});
console.log('SignedUrl-->' + getObjectResult['SignedUrl']);
console.log('ActualSignedRequestHeaders-->' + JSON.stringify(getObjectResult['ActualSignedRequestHeaders']));

// Generate a signed URL for deleting an object.
var deleteObjectResult = obsClient.createSignedUrlSync({Method : 'DELETE', Bucket : 'bucketname', Key : 'objectkey'});
console.log('SignedUrl-->' + deleteObjectResult['SignedUrl']);
console.log('ActualSignedRequestHeaders-->' + JSON.stringify(deleteObjectResult['ActualSignedRequestHeaders']));