Get and update file meta information
Updated at:2025-11-03
File metadata, or object metadata, describes the attributes of files uploaded to BOS. It includes two types: HTTP standard attributes (HTTP headers) and user-defined metadata.
Get file meta information
The getObjectMetadat method can be used to obtain only the ObjectMetadata, not the object entity itself. Refer to Demo.
As shown in the following code:
Java
1ObjectMetadata objectMetadata = client.getObjectMetadata(bucketName, objectKey);
2 // View object metadata
3System.out.println("contentType: " + objectMetadata.getContentType() + "\n" +
4 "contentLength: " + objectMetadata.getContentLength() + "\n" +
5 "contentMd5: " + objectMetadata.getContentMd5() + "\n" +
6 "etag: " + objectMetadata.getETag() + "\n" +
7 "storageClass: " + objectMetadata.getStorageClass() + "\n");
The parameters available for calling in the getObjectMetadata parsing class are:
| Parameters | Description |
|---|---|
| contentType | Object type |
| contentLength | Object size |
| contentMd5 | Object MD5 |
| etag | The HTTP protocol entity tag of object |
| storageClass | Storage class of the object |
| userMetadata | If userMetadata custom meta is specified in PutObject, this item will be returned |
| xBceCrc | If the CRC value (Cyclic Redundancy Check code) of the object is specified in PutObject, this item will be returned |
Modify file meta information
BOS modifies object metadata by copying the object. When copying, set the destination bucket and object as the source bucket and object, then apply the new metadata. If new metadata is not specified, an error will occur.
Java
1 public void setObjectMeta(BosClient client, String bucketName, String objectKey, ObjectMetadata newObjectMetadata) {
2
3 CopyObjectRequest request = new CopyObjectRequest(bucketName, objectKey, bucketName, objectKey);
4 //Set new ObjectMetadata
5 request.setNewObjectMetadata(newObjectMetadata);
6 // Copy Object
7 CopyObjectResponse copyObjectResponse = client.copyObject(request);
8 // Print results
9 System.out.println("ETag: " + copyObjectResponse.getETag() + " LastModified: " + copyObjectResponse.getLastModified());
10 }
