Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

updating headers of every file in an amazon s3 bucket

updating headers of every file in an amazon s3 bucket

Problem

I have a large number of files that have incorrect mimetypes in a Bucket, as well as no expires set.

How can I change them all?

I'm using Knox:

https://github.com/LearnBoost/knox

I'm trying to iterate over it. How do I get a list of all files in a folder?

When I do this

  client.get('/folder').on('response', function(res){
    console.log(res)
    res.on('data', function(chunk){
      console.log(chunk);
    });
  }).end();

I see osmething about an xml file, how do I access it?

Problem courtesy of: Harry

Solution

It looks like the library you have chosen does not have any native support for listing buckets. You will need to construct the list requests and parse the XML yourself - documentation for the underlying REST API can be found in the S3 API documentation.

Once you get a list of objects, you can use the S3 Copy Request functionality to update metadata. Just apply this patch, then pass x-amz-metadata-directive: REPLACE as a header to a copy request specifying the same key as source and destination (the source must specify the bucket as well!), plus any other headers you want to set.

Solution courtesy of: bdonlan

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

updating headers of every file in an amazon s3 bucket

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×