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

Torch Object Storage

Copy page
Download PDF
Manage Objects
Object Metadata Management (Browser.js SDK)
Copy page
Download PDF
Object Metadata Management (Browser.js SDK)
Object metadata refers to the description of an object's properties, which includes both HTTP standard attributes (HTTP Header) and user-defined metadata (User Meta).​
Notes​
  • To prevent the exposure of your Volcengine account credentials (namely, AccessKey ID and AccessKey Secret) in browser environments, it is strongly recommended that you 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's external services. For information about Endpoints supported by TOS, please refer to Access Domain Name Endpoint.​
  • Only the object owner has permission to set object metadata.​
  • When setting user-defined metadata, the Key must consist only of lowercase English letters and cannot contain spaces or other special characters.​
Parameters​
The TOS Browser SDK enables users to add and modify metadata for objects that have already been uploaded. TOS supports carrying the following request headers to modify object metadata. When downloading an object or performing a HEAD request, these values are set in the HTTP header and returned to the client. The request headers are as follows:​
​
​
Description​
Content-Type​
Object content type,​
Cache-Control​
Specifies the caching behavior when the object is downloaded.​
Expires​
Specifies the cache expiration time as defined in RFC 2616.​
Content-Disposition​
Specifies the default filename of the object when downloaded.​
Content-Encoding​
Specifies the content encoding of the object when downloaded.​
Content-Language​
Specifies the content language of the object when downloaded.​
x-tos-meta-*​
Metadata information set when setting the Meta field using the SDK. When this object is queried, the metadata will be included in the Header of the returned message.​
​
Sample Code​
Configuring Metadata Information During Standard Upload​
​
<!DOCTYPE html>​
<html lang="en">​
<head>​
<meta charset="UTF-8" />​
<title>Document</title>​
</head>​
<body>​
<button id="upload">Upload</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 type="text/javascript">​
const client = new TOS({​
region: yourRegion,​
endpoint: yourEndpoint,​
accessKeyId: yourAccessKey,​
accessKeySecret: yourSecretKey,​
stsToken: yourSecurityToken,​
bucket: examplebucket,​
});​
const objectName = 'exampledir/putObjectobject.txt';​
​
const upload = document.getElementById('upload');​
upload.addEventListener('click', async () => {​
const data = document.getElementById('file').files[0];​
console.log('data', data);​
​
try {​
const result = await client.uploadFile({​
key: objectName,​
file: data,​
headers: {​
'content-type': 'text/plain',​
expires: new Date('2028/01/01'),​
},​
});​
console.log(result);​
​
const headobject = await client.headObject({​
bucket: examplebucket,​
key: objectName,​
});​
// object info​
console.log('object info:', headobject.data);​
} catch (e) {​
console.log(e);​
}​
});​
</script>​
</body>​
</html>​
​
Set object metadata information using SetObjectMeta.​
​
<!DOCTYPE html>​
<html lang="en">​
<head>​
<meta charset="UTF-8" />​
<title>Document</title>​
</head>​
<body>​
<button id="upload">Upload</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 type="text/javascript">​
const client = new TOS({​
region: yourRegion,​
endpoint: yourEndpoint,​
accessKeyId: yourAccessKey,​
accessKeySecret: yourSecretKey,​
stsToken: yourSecurityToken,​
bucket: bucketName,​
});​
const objectName = 'exampledir/putObjectobject.txt';​
​
const main = async () => {​
const { data } = await client.headObject({​
bucket: bucketName,​
key: objectName,​
});​
console.log('object info:', data);​
console.log('object content-type:', data['content-type']);​
console.log('object expires:', data.expires);​
​
await client.setObjectMeta({​
bucket: bucketName,​
key: objectName,​
headers: {​
'Content-Language': 'zh-cn',​
'Content-Type': 'text/html',​
Expires: new Date('2030'),​
},​
});​
​
const { data: newData } = await client.headObject({​
bucket: bucketName,​
key: objectName,​
});​
console.log('object info:', newData);​
console.log('object content-type:', newData['content-type']);​
console.log('object expires:', newData.expires);​
console.log('object content-language:', newData['content-language']);​
};​
​
main();​
</script>​
</body>​
</html>​
​
Query Object Metadata (Determine Whether the Object Exists)​
warning​
Before obtaining object metadata, you must have the tos:GetObject permission. For more information, see IAM Policy Overview.​
​
<!DOCTYPE html>​
<html lang="en">​
<head>​
<meta charset="UTF-8" />​
<title>Document</title>​
</head>​
<body>​
<button id="upload">Upload</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: bucketName,​
});​
const objectName = 'exampledir/putObjectobject.txt';​
​
const main = async () => {​
const { data } = await client.headObject({​
bucket: bucketName,​
key: objectName,​
});​
console.log('object info:', data);​
};​
​
main();​
</script>​
</body>​
</html>​
​
​
Last updated: 2025.09.22 18:55:46