简体   繁体   English

在 S3 中更改所选文件的元数据

[英]Change meta-data on selected files in S3

I found a bunch of image files that has the wrong extension.我发现一堆扩展名错误的图像文件。 Due to the way the website is made, they must have a .jpg extension.由于网站的制作方式,它们必须具有.jpg扩展名。 But some of them are png files.但其中一些是png文件。

So I made a quick list of fake JPEG files ls public/assets/image/*.jpg | xargs file --mime | grep -v jpeg所以我快速列出了伪造的 JPEG 文件ls public/assets/image/*.jpg | xargs file --mime | grep -v jpeg ls public/assets/image/*.jpg | xargs file --mime | grep -v jpeg ls public/assets/image/*.jpg | xargs file --mime | grep -v jpeg and found https://stackoverflow.com/a/25825362/205696 that has an example of how to use the aws-cli tool to change the Cache-Control header (I want to change the Content-Type header). ls public/assets/image/*.jpg | xargs file --mime | grep -v jpeg and found https://stackoverflow.com/a/25825362/205696 that has an example of how to use the aws-cli tool to change the Cache-Control header (I want to change the Content-Type header) .

According to the aws s3 sync help man page, the syntax is sync <LocalPath> <S3Uri> or <S3Uri> <LocalPath> or <S3Uri> <S3Uri> .根据aws s3 sync help手册页,语法是sync <LocalPath> <S3Uri> or <S3Uri> <LocalPath> or <S3Uri> <S3Uri> Since I do want to sync any files from my machine, I opt for the last syntax aws s3 sync <S3Uri> <S3Uri> .因为我确实想从我的机器同步任何文件,所以我选择了最后一种语法aws s3 sync <S3Uri> <S3Uri>

However doing:但是这样做:

aws s3 sync s3://firefund-assets/underathens4.jpg s3://firefund-assets/underathens4.jpg --content-type image/png

does not seem to change anything.似乎没有任何改变。 The underathens4.jpg file still has System defined Content-Type image/jpeg ... and there is nothing written to stdout. underathens4.jpg 文件仍然具有System defined Content-Type image/jpeg ...并且没有任何内容写入标准输出。

If I can change the meta-data for a file in S3, then I can simply do cat fakeJpegs.txt | sed 's/public\/assets\/image\///' | xargs -i aws s3 sync s3://firefund-assets/'{}' s3://firefund-assets/'{}' --content-type image/png如果我可以更改 S3 中文件的元数据,那么我可以简单地执行cat fakeJpegs.txt | sed 's/public\/assets\/image\///' | xargs -i aws s3 sync s3://firefund-assets/'{}' s3://firefund-assets/'{}' --content-type image/png cat fakeJpegs.txt | sed 's/public\/assets\/image\///' | xargs -i aws s3 sync s3://firefund-assets/'{}' s3://firefund-assets/'{}' --content-type image/png

I do not want to re-upload any files.我不想重新上传任何文件。 In that case, I could use s3.console.aws.amazon.com and do the change manually.在这种情况下,我可以使用 s3.console.aws.amazon.com 并手动进行更改。 I just want to have a little script to do this occasionally..我只是想偶尔有一个小脚本来做这个..

Change the default content type on multiple files that have been uploaded to a AWS S3 bucket is related but suggest uploading the files again.更改已上传到 AWS S3 存储桶的多个文件的默认内容类型是相关的,但建议再次上传文件。

You can copy an object over itself while specifying new information.您可以在指定新信息的同时将 object 复制到自身之上

Use the cp command rather than the sync command:使用cp命令而不是sync命令:

aws s3 cp s3://firefund-assets/file.jpg s3://firefund-assets/file.jpg --content-type image/png

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM