Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

which is best approach to store images?

Tags:

mongodb

We are developing web application using mongodb and scala. We want to store Images uploaded by users. We have two options

  1. Storing Image directly in mongodb database using GridFS.

  2. Storing Images in folder on server.And store only path of that image in database.

Which is best approach so that time required to download the image is less?

like image 881
Sumit Deshpande Avatar asked May 28 '13 06:05

Sumit Deshpande


1 Answers

Normally, you want to separate static images from your application server for several reasons:

  • You don't want to use bandwidth / memory / CPU time serving images on your live application server: you want to save that for your app
  • It makes it easier to scale up the image serving, using something like Amazon S3, a big fileserver cluster and/or a caching CDN
  • Typical databases are not well optimised for storing images

Given all the above, I'd suggest keeping the images separate, and only storing the path (or lookup ID) of the image in your database.

like image 108
mikera Avatar answered Sep 21 '22 23:09

mikera