8

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?

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
Sumit Deshpande
  • 105
  • 3
  • 11
  • 1
    This question has gone round the tree many times, a quick search on this site will provide better answers than the ones below. i.e.: http://stackoverflow.com/questions/13457784/storage-for-millions-of-images and http://stackoverflow.com/questions/15030532/mongodb-as-file-storage – Sammaye May 28 '13 at 07:23

2 Answers2

7

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.

mikera
  • 105,238
  • 25
  • 256
  • 415
  • 10
    Hmm you don't take the considerations of MongoDB into context at all here, you just slap the pretty much default answer as you would to using blobs in MySQL. – Sammaye May 28 '13 at 07:29
2

Choose the second option

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

For this purpose, You can use gem mongoid-paperclip

This is an awesome gem and simple to implement.

Jyothu
  • 3,104
  • 17
  • 26