<meta charset="UTF-8" />
<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({
accessKeyId: yourAccessKey,
accessKeySecret: yourSecretKey,
stsToken: yourSecurityToken,
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);
const partSize = 5 * 1024 * 1024;
const result = await client.uploadFile({
const preview = document.getElementById('preview');
preview.addEventListener('click', async () => {
const result = await client.getPreSignedUrl({
const download = document.getElementById('download');
download.addEventListener('click', async () => {
const filename = 'examplefile.txt';
const result = await client.getPreSignedUrl({
contentDisposition: `attachment; filename=${filename}`,