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

Torch Object Storage

Copy page
Download PDF
Download Object
Standard Download (Browser.js SDK)
Copy page
Download PDF
Standard Download (Browser.js SDK)
The GetObject method enables downloading objects from a specified bucket. Before using this interface, ensure that you have read access to the object. When using the download interface, you can obtain current download data progress information by configuring a progress bar callback.​
Notes​
  • To prevent exposure of your Volcengine account credentials (namely, AccessKey ID and AccessKey Secret) in browser environments, it is strongly recommended to perform TOS-related operations using temporary access credentials. For detailed instructions, please refer to Using STS Temporary AK/SK+Token to Access Volcengine TOS.​
  • The Endpoint is the access domain name for TOS external services. For information on endpoints supported by TOS, please refer to Access Domain Endpoint.​
  • Before downloading an object, you must have the tos:GetObject permission. For more information, please refer to the Permission Configuration Guide.​
  • For buckets with versioning enabled, you must have the tos:GetObjectVersion permission to download a specified version of an object. For more information, please refer to the Permission Configuration Guide.​
  • If an application downloads the same object in large quantities simultaneously, your access speed will be subject to limitations imposed by TOS bandwidth and geographic restrictions. We recommend that you use CDN to enhance the performance while reducing your costs. For more information on accessing TOS through CDN, see Accelerating Access to TOS Resources Using CDN.​
Sample Code​
The following sample code is used to obtain the preview and download URL for the file exampleobject.txt in examplebucket.​
​
<!DOCTYPE html>​
<html lang="en">​
<head>​
<meta charset="UTF-8" />​
<title>Document</title>​
</head>​
<body>​
<button id="upload">Upload</button>​
<button id="preview">Get the preview URL</button>​
<button id="download">Get the download URL</button>​
<input id="file" type="file" />​
<script src="https://tos-public.volccdn.com/obj/volc-tos-public/@volcengine/tos-sdk@latest/browser/tos.umd.production.min.js"></script>​
<script src="./const.js"></script>​
<script type="text/javascript">​
const client = new TOS({​
region: yourRegion,​
endpoint: yourEndpoint,​
accessKeyId: yourAccessKey,​
accessKeySecret: yourSecretKey,​
stsToken: yourSecurityToken,​
bucket: examplebucket,​
});​
const name = 'exampledir/exampleobject.txt';​
​
const upload = document.getElementById('upload');​
upload.addEventListener('click', async () => {​
const data = document.getElementById('file').files[0];​
console.log('data', data);​
​
try {​
const partSize = 5 * 1024 * 1024;​
​
const result = await client.uploadFile({​
key: name,​
file: data,​
partSize,​
});​
console.log(result);​
} catch (e) {​
console.log(e);​
}​
});​
​
const preview = document.getElementById('preview');​
preview.addEventListener('click', async () => {​
try {​
const result = await client.getPreSignedUrl({​
key: name,​
expires: 3600,​
});​
console.log(result);​
} catch (e) {​
console.log(e);​
}​
});​
​
const download = document.getElementById('download');​
download.addEventListener('click', async () => {​
try {​
const filename = 'examplefile.txt';​
const result = await client.getPreSignedUrl({​
key: name,​
expires: 3600,​
response: {​
contentDisposition: `attachment; filename=${filename}`,​
},​
});​
console.log(result);​
} catch (e) {​
console.log(e);​
}​
});​
</script>​
</body>​
</html>​
​
​
Last updated: 2025.09.22 18:55:46