Best practices for storing images in Amazon S3 and saving in MySQL

3

I'm modeling a database, however I'm in doubt as to how I'll handle this part of saving the image in Amazon S3 and referencing it easily in the database.

I want to save the URL of the image (hosted on Amazon S3) in a field called "image_url" from bd.

One of my doubts is:

How do I generate multiple versions of image dimensions (sm, md, lg, original), and are able to save their url in the database? Should I create a column for each version of the image? Ex: image_url_sm, image_url_md, image_url_lg, image_url_original. In my opinion this looks like a bad database practice.

Here is my current table:

    
asked by anonymous 24.10.2015 / 14:29

1 answer

2

I would particularly try not to keep any of it in the bank. I would create a GUID for each record and make the URL of each image be derived from that GUID. Example of a record:

id: 123
name: "Eletrônicos"
image_key: "fdb3a9ba-b5e6-4d56-b703-27adb55c6f92"
etc...

In S3 I would create and save each version of the image:

  • meubucket / categories / images / fdb3a9ba-b5e6-4d56-b703-27adb55c6f92.original.png
  • meubucket / categories / images / fdb3a9ba-b5e6-4d56-b703-27adb55c6f92.sm.png
  • meubucket / categories / images / fdb3a9ba-b5e6-4d56-b703-27adb55c6f92.md.png
  • meubucket / categories / images / fdb3a9ba-b5e6-4d56-b703-27adb55c6f92.lg.png

The initial part of the URL will be http://meubucket.s3-website-us-east-1.amazonaws.com/categories/images and you can put this value in some configuration file if you need to change later or you have more than one environment of that application running (eg: Production x Integration) p>

If you are sure that id of the registry never changes, you can even use it in place of the GUID, but I find it more peaceful using the GUID.

    
24.10.2015 / 17:45