I am building a social media application that uses multiple user-uploaded images. I was told that the best tool for handling user-uploading images is Cloudinary, but if possible I want to directly store images in my database. I heard that databases have poor horizontal scaling, which is why solutions like cloudinary are pushed. Is it true that it is a bad idea to have images stored in mongodb? I do not want to use other APIs like cloudinary.
CodePudding user response:
Ussually image URL is stored in database because it always takes less space than whole image data. For example Wordpress stores images on server in uploads folder and in database you can only find URL plus title, type, and some additional data, but not whole image file.
You don't have to use cloud services to store your images, but it can be faster than loading images from your server. Saving every image in database is definetly not a good idea.
CodePudding user response:
It appears good to store image or any BLOB
in database in development, as it would organise very well with other associated data or transaction, However, there are caveats of storing BOLOB
(binary, image, ...) in database,
- non-indexable.
- non-searchable.
- non-compressible.
- Manipulations not easy.
Still, you can store but it will perform poorly at scale and in that case you should avoid storing image in database.
Storing image in any could provider's CDN service becomes best choice for performance including other features of image optimisations.