Using a Temporary URL for Authorized Access
If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the API Reference
ObsClient allows you to create a URL whose Query parameters are carried with authentication information by specifying the AK and SK, HTTP method, and request parameters. You can provide other users with this URL for temporary access. When generating a URL, you need to specify the validity period of the URL to restrict the access duration of visitors.
If you want to grant other users the permission to perform other operations on buckets or objects (for example, upload or download objects), generate a URL with the corresponding request (for example, to upload an object using the URL that generates the PUT request) and provide the URL for other users.
The following table lists operations can be performed through a signed URL.
|
Operation |
HTTP Request Method |
Special Operator (Sub-resource) |
Bucket Name Required |
Object Name Required |
|---|---|---|---|---|
|
PUT Bucket |
PUT |
N/A |
Yes |
No |
|
GET Buckets |
GET |
N/A |
No |
No |
|
DELETE Bucket |
DELETE |
N/A |
Yes |
No |
|
GET Objects |
GET |
N/A |
Yes |
No |
|
GET Object versions |
GET |
versions |
Yes |
No |
|
List Multipart uploads |
GET |
uploads |
Yes |
No |
|
Obtain Bucket Metadata |
HEAD |
N/A |
Yes |
No |
|
GET Bucket location |
GET |
location |
Yes |
No |
|
GET Bucket storageinfo |
GET |
storageinfo |
Yes |
No |
|
PUT Bucket quota |
PUT |
quota |
Yes |
No |
|
GET Bucket quota |
GET |
quota |
Yes |
No |
|
Set Bucket storagePolicy |
PUT |
storagePolicy |
Yes |
No |
|
GET Bucket storagePolicy |
GET |
storagePolicy |
Yes |
No |
|
PUT Bucket acl |
PUT |
acl |
Yes |
No |
|
GET Bucket acl |
GET |
acl |
Yes |
No |
|
PUT Bucket logging |
PUT |
logging |
Yes |
No |
|
GET Bucket logging |
GET |
logging |
Yes |
No |
|
PUT Bucket policy |
PUT |
policy |
Yes |
No |
|
GET Bucket policy |
GET |
policy |
Yes |
No |
|
DELETE Bucket policy |
DELETE |
policy |
Yes |
No |
|
PUT Bucket lifecycle |
PUT |
lifecycle |
Yes |
No |
|
GET Bucket lifecycle |
GET |
lifecycle |
Yes |
No |
|
DELETE Bucket lifecycle |
DELETE |
lifecycle |
Yes |
No |
|
PUT Bucket website |
PUT |
website |
Yes |
No |
|
GET Bucket website |
GET |
website |
Yes |
No |
|
DELETE Bucket website |
DELETE |
website |
Yes |
No |
|
PUT Bucket versioning |
PUT |
versioning |
Yes |
No |
|
GET Bucket versioning |
GET |
versioning |
Yes |
No |
|
PUT Bucket cors |
PUT |
cors |
Yes |
No |
|
GET Bucket cors |
GET |
cors |
Yes |
No |
|
DELETE Bucket cors |
DELETE |
cors |
Yes |
No |
|
PUT Bucket notification |
PUT |
notification |
Yes |
No |
|
GET Bucket notification |
GET |
notification |
Yes |
No |
|
PUT Bucket tagging |
PUT |
tagging |
Yes |
No |
|
GET Bucket tagging |
GET |
tagging |
Yes |
No |
|
DELETE Bucket tagging |
DELETE |
tagging |
Yes |
No |
|
PUT Object |
PUT |
N/A |
Yes |
Yes |
|
Append Object |
POST |
append |
Yes |
Yes |
|
GET Object |
GET |
N/A |
Yes |
Yes |
|
PUT Object - Copy |
PUT |
N/A |
Yes |
Yes |
|
DELETE Object |
DELETE |
N/A |
Yes |
Yes |
|
DELETE Objects |
POST |
delete |
Yes |
Yes |
|
Obtain Object Metadata |
HEAD |
N/A |
Yes |
Yes |
|
PUT Object acl |
PUT |
acl |
Yes |
Yes |
|
GET Object acl |
GET |
acl |
Yes |
Yes |
|
Initiate Multipart Upload |
POST |
uploads |
Yes |
Yes |
|
PUT Part |
PUT |
N/A |
Yes |
Yes |
|
PUT Part - Copy |
PUT |
N/A |
Yes |
Yes |
|
List Parts |
GET |
N/A |
Yes |
Yes |
|
Complete Multipart Upload |
POST |
N/A |
Yes |
Yes |
|
DELETE Multipart upload |
DELETE |
N/A |
Yes |
Yes |
|
POST Object restore |
POST |
restore |
Yes |
Yes |
To access OBS using a temporary URL generated by the OBS Node.js SDK, perform the following steps:
- Call ObsClient.createSignedUrlSync to generate a signed URL.
- Use any HTTP library to make an HTTP/HTTPS request to OBS.
The following content provides examples of accessing OBS using a temporary URL, including bucket creation, as well as object upload, download, listing, and deletion.
Creating a Bucket
// Import the OBS library.
// Use npm to install the client.
var ObsClient = require('esdk-obs-nodejs');
// Use source codes to install the client.
// var ObsClient = require('./lib/obs');
var http = require('http');
var urlLib = require('url');
var crypto = require('crypto');
// Create an instance of ObsClient.
var obsClient = new ObsClient({
access_key_id: '*** Provide your Access Key ***',
secret_access_key: '*** Provide your Secret Key ***',
server : 'http://your-endpoint'
});
let bucketName = 'bucketname';
let method = 'PUT';
let res = obsClient.createSignedUrlSync({Method : method, Bucket : bucketName});
let location = 'your-location';
let content = `<CreateBucketConfiguration><LocationConstraint>${location}</LocationConstraint></CreateBucketConfiguration>`;
// Make a PUT request to create a bucket.
var url = urlLib.parse(res.SignedUrl);
var req = http.request({
method : method,
host : url.hostname,
port : url.port,
path : url.path,
rejectUnauthorized : false,
headers : res.ActualSignedRequestHeaders || {}
});
console.log('Creating bucket using url:' + res.SignedUrl);
req.on('response', (serverback) => {
var buffers = [];
serverback.on('data', (data) => {
buffers.push(data);
}).on('end', () => {
if(serverback.statusCode < 300){
console.log('Creating bucket using temporary signature succeed.');
}else{
console.log('Creating bucket using temporary signature failed!');
console.log('status:' + serverback.statusCode);
console.log('\n');
}
buffers = Buffer.concat(buffers);
if(buffers.length > 0){
console.log(buffers.toString());
}
console.log('\n');
});
}).on('error',(err) => {
console.log('Creating bucket using temporary signature failed!');
console.log(err);
console.log('\n');
});
if(content){
req.write(content);
}
req.end();
Uploading an Object
// Import the OBS library.
// Use npm to install the client.
var ObsClient = require('esdk-obs-nodejs');
// Use source codes to install the client.
// var ObsClient = require('./lib/obs');
var http = require('http');
var urlLib = require('url');
var crypto = require('crypto');
// Create an instance of ObsClient.
var obsClient = new ObsClient({
access_key_id: '*** Provide your Access Key ***',
secret_access_key: '*** Provide your Secret Key ***',
server : 'http://your-endpoint'
});
let bucketName = 'bucketname';
let objectKey = 'objectname';
let method = 'PUT';
let res = obsClient.createSignedUrlSync({Method : method, Bucket : bucketName, Key: objectKey, Expires: 3600});
let content = 'Hello OBS';
//Make a PUT request to upload an object.
var url = urlLib.parse(res.SignedUrl);
var req = http.request({
method : method,
host : url.hostname,
port : url.port,
path : url.path,
rejectUnauthorized : false,
headers : res.ActualSignedRequestHeaders || {}
});
console.log('Creating object using url:' + res.SignedUrl);
req.on('response', (serverback) => {
var buffers = [];
serverback.on('data', (data) => {
buffers.push(data);
}).on('end', () => {
if(serverback.statusCode < 300){
console.log('Creating object using temporary signature succeed.');
}else{
console.log('Creating object using temporary signature failed!');
console.log('status:' + serverback.statusCode);
console.log('\n');
}
buffers = Buffer.concat(buffers);
if(buffers.length > 0){
console.log(buffers.toString());
}
console.log('\n');
});
}).on('error',(err) => {
console.log('Creating object using temporary signature failed!');
console.log(err);
console.log('\n');
});
if(content){
req.write(content);
}
req.end();
Downloading an Object
// Import the OBS library.
// Use npm to install the client.
var ObsClient = require('esdk-obs-nodejs');
// Use source codes to install the client.
// var ObsClient = require('./lib/obs');
var http = require('http');
var urlLib = require('url');
var crypto = require('crypto');
// Create an instance of ObsClient.
var obsClient = new ObsClient({
access_key_id: '*** Provide your Access Key ***',
secret_access_key: '*** Provide your Secret Key ***',
server : 'http://your-endpoint'
});
let bucketName = 'bucketname';
let objectKey = 'objectname';
let method = 'GET';
let res = obsClient.createSignedUrlSync({Method : method, Bucket : bucketName, Key: objectKey, Expires: 3600});
//Make a GET request to download an object.
var url = urlLib.parse(res.SignedUrl);
var req = http.request({
method : method,
host : url.hostname,
port : url.port,
path : url.path,
rejectUnauthorized : false,
headers : res.ActualSignedRequestHeaders || {}
});
console.log('Creating object using url:' + res.SignedUrl);
req.on('response', (serverback) => {
var buffers = [];
serverback.on('data', (data) => {
buffers.push(data);
}).on('end', () => {
if(serverback.statusCode < 300){
console.log('Getting object using temporary signature succeed.');
}else{
console.log('Getting object using temporary signature failed!');
console.log('status:' + serverback.statusCode);
console.log('\n');
}
buffers = Buffer.concat(buffers);
if(buffers.length > 0){
console.log(buffers.toString());
}
console.log('\n');
});
}).on('error',(err) => {
console.log('Getting object using temporary signature failed!');
console.log(err);
console.log('\n');
});
req.end();
Listing Objects
// Import the OBS library.
// Use npm to install the client.
var ObsClient = require('esdk-obs-nodejs');
// Use source codes to install the client.
// var ObsClient = require('./lib/obs');
var http = require('http');
var urlLib = require('url');
var crypto = require('crypto');
// Create an instance of ObsClient.
var obsClient = new ObsClient({
access_key_id: '*** Provide your Access Key ***',
secret_access_key: '*** Provide your Secret Key ***',
server : 'http://your-endpoint'
});
let bucketName = 'bucketname';
let method = 'GET';
let res = obsClient.createSignedUrlSync({Method : method, Bucket : bucketName, Expires: 3600});
// Make a GET request to obtain the object list.
var url = urlLib.parse(res.SignedUrl);
var req = http.request({
method : method,
host : url.hostname,
port : url.port,
path : url.path,
rejectUnauthorized : false,
headers : res.ActualSignedRequestHeaders || {}
});
console.log('Listing object using url:' + res.SignedUrl);
req.on('response', (serverback) => {
var buffers = [];
serverback.on('data', (data) => {
buffers.push(data);
}).on('end', () => {
if(serverback.statusCode < 300){
console.log('Listing object using temporary signature succeed.');
}else{
console.log('Listing object using temporary signature failed!');
console.log('status:' + serverback.statusCode);
console.log('\n');
}
buffers = Buffer.concat(buffers);
if(buffers.length > 0){
console.log(buffers.toString());
}
console.log('\n');
});
}).on('error',(err) => {
console.log('Listing object using temporary signature failed!');
console.log(err);
console.log('\n');
});
req.end();
Deleting an Object
// Import the OBS library.
// Use npm to install the client.
var ObsClient = require('esdk-obs-nodejs');
// Use source codes to install the client.
// var ObsClient = require('./lib/obs');
var http = require('http');
var urlLib = require('url');
var crypto = require('crypto');
// Create an instance of ObsClient.
var obsClient = new ObsClient({
access_key_id: '*** Provide your Access Key ***',
secret_access_key: '*** Provide your Secret Key ***',
server : 'http://your-endpoint'
});
let bucketName = 'bucketname';
let objectKey = 'objectname';
let method = 'DELETE';
let res = obsClient.createSignedUrlSync({Method : method, Bucket : bucketName, Key: objectKey, Expires: 3600});
// Make a DELETE request to delete the object.
var url = urlLib.parse(res.SignedUrl);
var req = http.request({
method : method,
host : url.hostname,
port : url.port,
path : url.path,
rejectUnauthorized : false,
headers : res.ActualSignedRequestHeaders || {}
});
console.log('Deleting object using url:' + res.SignedUrl);
req.on('response', (serverback) => {
var buffers = [];
serverback.on('data', (data) => {
buffers.push(data);
}).on('end', () => {
if(serverback.statusCode < 300){
console.log('Deleting object using temporary signature succeed.');
}else{
console.log('Deleting object using temporary signature failed!');
console.log('status:' + serverback.statusCode);
console.log('\n');
}
buffers = Buffer.concat(buffers);
if(buffers.length > 0){
console.log(buffers.toString());
}
console.log('\n');
});
}).on('error',(err) => {
console.log('Deleting object using temporary signature failed!');
console.log(err);
console.log('\n');
});
req.end();
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.
Last Article: Temporarily Authorized Access
Next Article: Versioning Management
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.