Harry
Harry

Reputation: 54949

updating headers of every file in an amazon s3 bucket

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?

Upvotes: 2

Views: 2066

Answers (1)

bdonlan
bdonlan

Reputation: 231133

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.

Upvotes: 5

Related Questions