Sumit Deshpande
Sumit Deshpande

Reputation: 105

which is best approach to store images?

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?

Upvotes: 8

Views: 2961

Answers (2)

Jyothu
Jyothu

Reputation: 3154

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.

Upvotes: 2

mikera
mikera

Reputation: 106351

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.

Upvotes: 7

Related Questions