How to set expires headers to all images in a bucket in Amazon S3

后端 未结 6 1087
予麋鹿
予麋鹿 2020-12-23 11:59

We have around 10,000+ images in a bucket in Amazon S3, how can I set the expires header on all of the images in one go?

相关标签:
6条回答
  • 2020-12-23 12:19

    You can make bulk changes to bucket files with third party apps that use the S3 API. Those apps will not set the headers using only one request, but will automate the 10,000+ required requests.

    The one I currently use is Cloudberry Explorer, which is a freeware utility to interact with your S3 buckets. In this tool I can select multiple files and specify HTTP headers that will be applied to all of them.

    enter image description here

    enter image description here

    An alternative would be to develop your own script or tool using the S3 API libraries.

    0 讨论(0)
  • 2020-12-23 12:23

    An alternative solution is to add response-expires parameter in your URL. It sets the Expires header of the response.

    See Request Parameters section in http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectGET.html for more detail.

    0 讨论(0)
  • 2020-12-23 12:27

    Pretty sure it's not possible to do this in a single request. Instead you'll have to make 10,000 PUT requests, one for each key, with the new headers/metadata you want along with the x-amz-copy-source header pointing to the same key (so that you don't need to re-upload the object). The link I provided goes into more detail on the PUT-copy operation, but it's pretty much the way to change object metadata on s3.

    0 讨论(0)
  • 2020-12-23 12:39

    Cyberduck will edit headers as well.

    1. Choose all the items
    2. command & i ( get info )
    3. Offers a GUI to edit various Headers with presets built in.

    Just processed 6000 images in one bucket without a hitch.

    0 讨论(0)
  • 2020-12-23 12:41

    Just a heads up that I found a great solution using the AWS CLI:

    aws s3 cp s3://bucketname/optional_path s3://bucketname/optional_path --recursive  --acl public-read  --metadata-directive REPLACE --cache-control max-age=2592000
    

    This will set the Cache-Control for 30 days. Note that you have the option to copy or replace the previous header data. Since AWS will automatically include the right meta content-type data for each media type and I had some bad headers I just chose to overwrite everything.

    0 讨论(0)
  • 2020-12-23 12:42
    1. Select the folder
    2. From the top menu, More
    3. Select Change Metadata
    4. Add Key as Expires
    5. Add Value as 2592000 (for example)
    0 讨论(0)
提交回复
热议问题