updating headers of every file in an amazon s3 bucket

こ雲淡風輕ζ 提交于 2020-01-02 09:55:53

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/7459122/updating-headers-of-every-file-in-an-amazon-s3-bucket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!