Which is best for storing images?

We are developing a web application using mongodb and scala. We want to save images uploaded by users. We have two options.

  • Saving an image directly to the mongodb database using GridFS.

  • Saving images in a folder on the server. And save only the path to this image in the database.

What is the best approach, so the time it takes to download the image is less?

+8
mongodb
source share
2 answers

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

  • You do not want to use the bandwidth / memory / CPU load time on your real application server: you want to save this for your application.
  • This simplifies image scaling using something like Amazon S3, a large file server and / or CDN caching
  • Typical databases are not optimized enough for image storage

Given all of the above, I suggest saving individual images and saving only the path (or search identifier) ​​of the image in your database.

+7
source share

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

It is a stunning stone and easy to implement.

+2
source share

All Articles