All Products
Search
Document Center

Object Storage Service:How to modify the object metadata information of the OSS service

Last Updated:Mar 20, 2026

OSS object metadata — including key values, directories, names, HTTP headers, and user-defined metadata — cannot be modified in place after upload. To update metadata, copy the object with the new metadata applied, then delete the original.

Two approaches are available:

  • Copy via API (recommended): Call CopyObject or UploadPartCopy to copy the object with updated metadata, then delete the original. This avoids downloading or re-uploading the object data.

  • Download, modify, and re-upload: Download the object, update the metadata locally, delete the original, and re-upload. This approach consumes significant time and bandwidth and is not recommended.

Update object metadata using CopyObject

The following example uses the OSS SDK for Java to copy an object from menu1/src_sample to menu2/dst_sample, then delete the original.

String bucketName = "bucket_sample";
String sourceKey = "menu1/src_sample";
String dstKey = "menu2/dst_sample";

OSSClient client = new OSSClient(ACCESS_ID, ACCESS_KEY, ACCESS_TOKEN);
client.copyObject(bucketName, sourceKey, bucketName, dstKey);
client.deleteObject(bucketName, sourceKey);

What's next