Harsha M V
Harsha M V

Reputation: 54949

Managing Versions of Images on Amazon S3 and MongoDB

I am have an app that will require to use Amazon S3 to host Images and its different sizes on it. I am looking forward to understand which is the best way to do this.

When a user uploads an Image i create 3 different sizes that are required at different parts of the site or the mobile app. In total i have 4 files of the same images.

Questions:

  1. How to store them in Amazon S3. any idea on how to rename these files to make it easier.
  2. Do i need to store the file names of all 4 file names in MongoDB ?

Upvotes: 0

Views: 141

Answers (2)

mnemosyn
mnemosyn

Reputation: 46301

You could simply append a short string, either the resolution or a usage-identifier like 'thumbnail', e.g.

foobar.jpg -> 2342342_thumb.jpg
           -> 2342342_gallery.jpg
           -> 2342342_full.jpg

That way, you won't need to store the name of the four files but just follow the convention.

Upvotes: 1

Mustafa Genç
Mustafa Genç

Reputation: 2579

You don't need to keep all file names in db. Just keep a parent folder name.

Lets say an image uploaded by a user has id 1234567(for sake of uniqueness. You may also use timestamp). Then create a folder named 1234567 and put all images with specific names like original, thumbnail, medium, large. And whenever you need a specific one just stream it.

Upvotes: 1

Related Questions