Using AWS S3 for photo storage

后端 未结 2 638
粉色の甜心
粉色の甜心 2021-02-09 12:13

I\'m going to be using S3 to store user uploaded photos. Obviously, I wont be serving the image files to user agents without resizing them down. However, not one size would do,

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-09 12:53

    Pre-generating different sizes and storing them in S3 is a fine approach, especially if you know what sizes you need, are likely to use all of the sizes for all of the images, and don't have so many images and sizes that the storage cost is excessive.

    Here's another approach I use when I don't want to pre-generate and store all the different sizes for every image, or when I don't know what sizes I will want to use in the future:

    1. Store the original size in S3.

    2. Run a web server that can generate any desired size from the original image on request.

    3. Stick a CDN (CloudFront) in front of the web server.

    Now, your web site or application can request a URL like /16x16/someimage.jpg from CloudFront. The first time this happens, CloudFront will get the resized image from your web server, but then CloudFront will cache the image and serve it for you, greatly reducing the amount of traffic that hits your web server.

    Here's a service that resizes images from arbitrary URLs, serving them through CloudFront: http://filter.to

提交回复
热议问题