Reputation: 4214
I just wanted to ask if there was a speedy of dynamically showing thumbnails of images uploaded on S3. Lets say profile pictures.
I have 3 sizes of these pictures being shown Actual, 150x150 and 25x25. At the moment I am dynamically resizing them on the fly on my server - not S3.
http://www.mydomain.com/images/25X25/image.jpg
Above is a URL that checks if a thumbnail exists and if not generates it. I allow only 3 sizes at the moment.
Soon we would be shifting to S3. Is such thing possible at S3 also - do I have to get the original image, resize it and then reupload on S3 - all on the fly - of course with cache enabled?
Or should I do this when I upload the actual image itself - make 2 more thumbnails (with easily readable filename lile image_25_25 and image_150_150) and upload those too along with it?
So eventually every upload results in
https://bucket.s3.amazonaws.com/image.jpg
https://bucket.s3.amazonaws.com/image_25_25.jpg
https://bucket.s3.amazonaws.com/image_150_150.jpg
Which do you think is a good option? Or Suggestions please - will be really thankfull to you all (err - always am - such an amazing place this is to get help!)
Cheers!
Upvotes: 0
Views: 4089
Reputation: 71384
I would think that your approach will largely depend on what your primary goals are for making this change, what sort of upload volume you are expecting to handle, what sort of typical hit rate you have on these thumbnails, and what your constraints are regarding cost of performing this thumbnailing (i.e server resources needed to do the processing and storage costs for storing).
If the #1 most important thing is to speed-up image download times for end users, regardless of cost, then building the thumbnails on upload would probably be the best choice (possibly along with the use of Cloudfront in front of the S3 bucket). This would also take your application out of the business of trying to dynamically serve requests for these images. One con is obviously that the upload process may take longer for the end user (if you need the files to be created and available in S3 before indicating success to the end user), and of course you end up having to tie up server resources and storage space for every single uploaded image, regardless as to whether the image will ever be used.
If your concerns are more about utilizing the minimum amount of resources and storage, then you could continue to take the approach of using the web application to handle the image requests and create the images as needed in S3. You could potentially use something like s3fs (with its caching functions turned on) to make these images available on a local mount of your application server to help speed up the process, but really I would advise against this dynamic serving of content approach if your overall goal is to provide the best user experience (i.e. quickest downloads).
Upvotes: 2