John Bachir John Bachir - 8 months ago 67
Ruby Question

How do I update a batch of S3 objects' metadata using ruby?

I need to change some metadata (Content-Type) on hundreds or thousands of objects on S3. What's a good way to do this with ruby? As far as I can tell there is no way to save only metadata with, the entire object must be re-saved. Seems like using the official sdk library would require me rolling a wrapper environment just for this one task.


You're right, the official SDK lets you modify the object metadata without uploading it again. What it does is copy the object but that's on the server so you don't need to download the file and re-upload it.

A wrapper would be easy to implement, something like

bucket.objects.each do |object|
  object.metadata['content-type'] = 'application/json'