Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I update metadata for an existing Amazon S3 file?

I need to update the cache control header in all AmazonS3's Cloud Files. However, I can't figure out how I do that using the jclouds API. I'm using apache jclouds plugin. And I got two related answers:

  • jclouds : how do I update metadata for an existing blob?
  • Set Expires header for an existing S3 object using AWS Java SDK

The first answer is suggesting to use SwiftKey Api class which is not available in grails's jcloud plugin. The second answer is using AWS java sdk for which there is already a grails wrapping plugin https://grails.org/plugin/aws-sdk but it doesn't support metadata update.

like image 222
Priyanshu Chauhan Avatar asked Sep 18 '15 07:09

Priyanshu Chauhan


People also ask

How do I update AWS metadata?

Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . Navigate to your Amazon S3 bucket or folder, and select the check box to the left of the names of the objects with metadata you want to edit. On the Actions menu, choose Edit actions, and choose Edit metadata.

Can we update file in S3 bucket?

It's not possible to append to an existing file on AWS S3. You can delete existing file and upload new file with same name.

Can S3 objects be updated?

You can use the S3 Versioning feature to preserve, retrieve, and restore every version of every object stored in your buckets.


1 Answers

It is possible to change the metadata by performing an object copy (see How to update metadata using Amazon S3 SDK):

ObjectMetadata metadataCopy = new ObjectMetadata(); // copy previous metadata metadataCopy.addUserMetadata("newmetadata", "newmetadatavalue");  CopyObjectRequest request = new CopyObjectRequest(bucketName, existingKey, bucketName, existingKey)       .withNewObjectMetadata(metadataCopy);  amazonS3Client.copyObject(request); 

Whether this is philosophically an "update" is up to you to decide.

like image 62
Dan Gravell Avatar answered Oct 02 '22 12:10

Dan Gravell