When a user uploads an image to my site, I save multiple copies of the image in different sizes to S3. Is it possible to save one copy of the image and access the different sizes with URL variables?
I would prefer something like this:
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
As opposed to this:
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
I do not want to download large images unnecessarily.
No, you cannot use query parameters to access different objects (files) on S3.
Just like you suggested yourself, you have to come up with a naming schema. Your suggestion was:
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
If you don't like this, an alternative:
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
Or:
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
Or, if you are willing to manually set the content type of each uploaded object, even:
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
How you name your image objects in the S3 bucket doesn't really matter, but your web application will have to know how to put an image URL together in order to link to the desired format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With