You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
Pre-signature Mechanism
Standard Presigned Signature (Browser.js SDK)
Copy page
Download PDF
Standard Presigned Signature (Browser.js SDK)
By default, TosClient includes a signature in the request header when initiating requests to the server. The SDK also supports generating signed URLs, which users can use to initiate HTTP requests directly or share with third parties to grant access authorization.​
Presigned Overview​
By default, TosClient includes a signature in the request header when initiating a request to the server. The SDK also supports generating signed URLs, which can be used to initiate HTTP requests directly or shared with third parties to enable access authorization.​
Sample Code​
Uploading Objects Using Pre-Signed URLs​
The following code is used to upload objects to a specified bucket via a pre-signed URL.​
​
<!DOCTYPE html>​
<html lang="en">​
<head>​
<meta charset="UTF-8" />​
<title>Document</title>​
</head>​
<body>​
<script src="https://tos-public.volccdn.com/obj/volc-tos-public/@volcengine/tos-sdk@latest/browser/tos.umd.production.min.js"></script>​
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.4.0/axios.min.js"></script>​
<script type="text/javascript">​
const client = new TOS({​
region: yourRegion,​
endpoint: yourEndpoint,​
accessKeyId: yourAccessKey,​
accessKeySecret: yourSecretKey,​
stsToken: yourSecurityToken,​
bucket: examplebucket,​
});​
const objectName = 'exampledir/preSignedUrl-put.txt';​
​
const main = async () => {​
const url = client.getPreSignedUrl({​
method: 'PUT',​
bucket: examplebucket,​
key: objectName,​
});​
console.log('PreSignedUrl:', url);​
​
const uploadResult = await axios.put(url, 'hello world from PreSignedUrl');​
​
const { data } = await client.headObject({​
bucket: examplebucket,​
key: objectName,​
});​
​
console.log('object size:', data, data['content-length']);​
};​
​
main();​
</script>​
</body>​
</html>​
​
Downloading Objects Using Pre-Signed URLs​
The following code is used to download objects from a specified bucket using a pre-signed URL.​
​
<!DOCTYPE html>​
<html lang="en">​
<head>​
<meta charset="UTF-8" />​
<title>Document</title>​
</head>​
<body>​
<script src="https://tos-public.volccdn.com/obj/volc-tos-public/@volcengine/tos-sdk@latest/browser/tos.umd.production.min.js"></script>​
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.4.0/axios.min.js"></script>​
<script type="text/javascript">​
const client = new TOS({​
region: yourRegion,​
endpoint: yourEndpoint,​
accessKeyId: yourAccessKey,​
accessKeySecret: yourSecretKey,​
stsToken: yourSecurityToken,​
bucket: examplebucket,​
});​
const objectName = 'exampledir/preSignedUrl-put.txt';​
​
const main = async () => {​
const url = client.getPreSignedUrl({​
method: 'GET',​
bucket: examplebucket,​
key: objectName,​
});​
console.log('PreSignedUrl:', url);​
​
const result = await axios.get(url);​
console.log('get result:', result.data);​
};​
​
main();​
</script>​
</body>​
</html>​
​
Deleting Objects Using Pre-Signed URLs​
The following code is used to delete objects in a specified bucket via a pre-signed URL.​
​
<!DOCTYPE html>​
<html lang="en">​
<head>​
<meta charset="UTF-8" />​
<title>Document</title>​
</head>​
<body>​
<script src="https://tos-public.volccdn.com/obj/volc-tos-public/@volcengine/tos-sdk@latest/browser/tos.umd.production.min.js"></script>​
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.4.0/axios.min.js"></script>​
<script type="text/javascript">​
const client = new TOS({​
region: yourRegion,​
endpoint: yourEndpoint,​
accessKeyId: yourAccessKey,​
accessKeySecret: yourSecretKey,​
stsToken: yourSecurityToken,​
bucket: examplebucket,​
});​
const objectName = 'exampledir/preSignedUrl-put.txt';​
​
const main = async () => {​
const url = client.getPreSignedUrl({​
method: 'DELETE',​
bucket: examplebucket,​
key: objectName,​
});​
console.log('PreSignedUrl:', url);​
​
const result = await axios.delete(url);​
console.log('delete result:', result);​
};​
​
main();​
</script>​
</body>​
</html>​
​
​
Last updated: 2025.09.22 18:55:46