Modifying Object Metadata
API Description
You can use this API to send a PUT request to the object in a specified bucket to modify its metadata.
Method Definition
ObsClient.setObjectMetadata
Request Parameter
| Field | Type | Optional or Mandatory | Description |
|---|---|---|---|
| Bucket | String | Mandatory | Bucket name |
| Key | String | Mandatory | Object name |
| VersionId | String | Optional | Object version ID |
| Origin | String | Optional | Origin of the cross-domain request specified by the pre-request. Generally, it is a domain name. |
| RequestHeader | String | Optional | HTTP headers in the cross-domain request |
| MetadataDirective | String | Mandatory | Metadata operation indicator. The value can be REPLACE_NEW or REPLACE. REPLACE_NEW: If the metadata of an existing value is replaced, a value is assigned to the metadata that does not have a value. The metadata that is not specified remains unchanged. REPLACE: Use the header field carried in the current request to replace the original metadata. The metadata that is not specified (except StorageClass) will be deleted. |
| CacheControl | String | Optional | Specifies the cache behavior of the web page when the object is downloaded. |
| ContentDisposition | String | Optional | Specifies the name of the object when it is downloaded. |
| ContentLanguage | String | Optional | Specifies the content language format when an object is downloaded. |
| ContentEncoding | String | Optional | Specifies the content encoding format when an object is being uploaded. |
| ContentType | String | Optional | Object file type |
| Expires | String | Optional | Request expiration time |
| Metadata | Object | Optional | Customized metadata of the object |
| StorageClass | String | Optional | Specifies the storage class of an object. OBS provides three storage classes: Standard (STANDARD), Infrequent Access (WARM), and Archive (COLD). Therefore, values for this element can be STANDARD, WARM, and COLD. The spell of these values is case sensitive. |
| WebsiteRedirectLocation | String | Optional | When the bucket is configured with the website redirection, the request for obtaining the object can be redirected to another object or an external URL in the bucket. |
Returned Result (InterfaceResult)
| Field | Type | Description |
|---|---|---|
| RequestId | String | Request ID returned by the OBS server |
| MetadataDirective | String | Metadata operation indicator. The value can be REPLACE_NEW or REPLACE. |
| CacheControl | String | Specifies the cache behavior of the web page when the object is downloaded. |
| Content-Disposition | String | Object ETag |
| Content-Encoding | String | Object version ID |
| WebsiteRedirectLocation | String | Location where the object is redirected to, when the bucket is configured with website hosting |
| StorageClass | String | Storage class of the object. When the storage class is Standard, the value is null. |
| Content-Language | String | If Origin in the request meets the CORS rules of the bucket, AllowedOrigin in the CORS rules is returned. |
| Expires | String | If AccessControlRequestHeaders in the request meets the CORS rules of the bucket, AllowedHeader in the CORS rules is returned. |
| Metadata | Object | Customized metadata of the object |
Sample Code
obsClient.setObjectMetadata({
Bucket:'bucketname',
Key : 'objectkey',
CacheControl: 'CacheControl',
ContentDisposition: 'ContentDisposition',
ContentLanguage: 'ContentLanguage',
ContentEncoding: 'ContentEncoding',
ContentType: 'ContentType',
StorageClass: 'StorageClass',
Expires: 'Expires',
MetadataDirective: 'REPLACE_NEW',
Metadata: 'Metadata'
},(err, result) => {
if(err){
console.error('Error-->' + err);
}else{
if(result.CommonMsg.Status < 300){
console.log('RequestId-->' + result.InterfaceResult.RequestId);
console.log('MetadataDirective-->' + result.InterfaceResult.MetadataDirective);
console.log('CacheControl-->' + result.InterfaceResult.CacheControl);
console.log('ContentDisposition-->' + result.InterfaceResult.ContentDisposition);
console.log('ContentLanguage-->' + result.InterfaceResult.ContentLanguage);
console.log('Metadata-->' + result.InterfaceResult.Metadata);
console.log('Expires-->' + result.InterfaceResult.Expires);
}else{
console.log('Status-->' + result.CommonMsg.Status);
}
}
}); Last Article: Obtain Object Metadata
Next Article: PUT Object acl
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.