AWS S3相同图像,不同大小

时间:2016-03-18 19:41:40

标签: html image amazon-web-services amazon-s3

当用户将图像上传到我的网站时,我会将不同尺寸的图像的多个副本保存到S3。是否可以保存图像的一个副本并使用URL变量访问不同的大小?

我更喜欢这样的事情:

https://s3-us-west-2.amazonaws.com/img.jpg?size=small
https://s3-us-west-2.amazonaws.com/img.jpg?size=medium
https://s3-us-west-2.amazonaws.com/img.jpg?size=large

与此相反:

https://s3-us-west-2.amazonaws.com/img1.jpg
https://s3-us-west-2.amazonaws.com/img2.jpg
https://s3-us-west-2.amazonaws.com/img3.jpg

我不想不必要地下载大图像。

2 个答案:

答案 0 :(得分:3)

不,您无法使用查询参数访问S3上的不同对象(文件)。

就像你自己建议的那样,你必须提出一个命名模式。你的建议是:

https://s3-us-west-2.amazonaws.com/bucketname/<imagename><size>.<ext>
- Example: -
https://s3-us-west-2.amazonaws.com/bucketname/img1.jpg
https://s3-us-west-2.amazonaws.com/bucketname/img2.jpg
https://s3-us-west-2.amazonaws.com/bucketname/img3.jpg

如果您不喜欢这样,可以选择:

https://s3-us-west-2.amazonaws.com/bucketname/<imagename>/<size>.<ext>

- Example: -
https://s3-us-west-2.amazonaws.com/bucketname/img/1.jpg
https://s3-us-west-2.amazonaws.com/bucketname/img/2.jpg
https://s3-us-west-2.amazonaws.com/bucketname/img/3.jpg
- or named sizes: -
https://s3-us-west-2.amazonaws.com/bucketname/img/small.jpg
https://s3-us-west-2.amazonaws.com/bucketname/img/medium.jpg
https://s3-us-west-2.amazonaws.com/bucketname/img/large.jpg

或者:

https://s3-us-west-2.amazonaws.com/bucketname/<imagename>-<size>.<ext>
- Example: -
https://s3-us-west-2.amazonaws.com/bucketname/img-1.jpg
https://s3-us-west-2.amazonaws.com/bucketname/img-2.jpg
https://s3-us-west-2.amazonaws.com/bucketname/img-3.jpg
- or named sizes: -
https://s3-us-west-2.amazonaws.com/bucketname/img-small.jpg
https://s3-us-west-2.amazonaws.com/bucketname/img-medium.jpg
https://s3-us-west-2.amazonaws.com/bucketname/img-large.jpg

或者,如果您愿意手动设置每个上传对象的内容类型,甚至:

https://s3-us-west-2.amazonaws.com/bucketname/<imagename>.<ext>/<size>
- Example with named sizes: -
https://s3-us-west-2.amazonaws.com/bucketname/img.jpg/small
https://s3-us-west-2.amazonaws.com/bucketname/img.jpg/medium
https://s3-us-west-2.amazonaws.com/bucketname/img.jpg/large

如何在S3存储桶中命名图像对象并不重要,但您的Web应用程序必须知道如何将图像URL放在一起才能链接到所需的格式。

答案 1 :(得分:2)

S3无法实现(因为S3不会计算其他格式,他们只会为您上传的文件提供服务)。但https://www.imgix.com可能会出现这种情况,这与您所描述的非常相似。