This topic describes how to modify the metadata of objects in OSS.
OSS objects include a lot of metadata, such as key values, directories, names, HTTP header, and user custom metadata. You may need to modify the corresponding data during uploading objects or later use. Refer to the following two solutions.
Method 1: Download objects to your local computer
Download the object to your local computer, delete the original object, and upload the object after the metadata change. This method is the most basic method, but it takes up a lot of time and consumes resources. Therefore, we recommend that you do not use this method.
Method 2: Copy objects through interfaces
You can call the CopyObjcet or UploadPartCopy operation to copy objects. You can modify the metadata of the object and then delete the object. We recommend that you use this method. Please refer to the following code. This topic uses SDK for Java to modify the directory and name of a file.
String bucketName = "bucket_sample";
String sourceKey = "menu1/src_sample";
String dstKey = "menu2/dst_sample";
OSSClient client = new OSSClient(ACCESS_ID, ACCESS_KEY, ACEESS_TOKEN);
client.copyObject(bucketName, sourceKey, bucketName, dstKey);
For more information, see the following documentation.