skip to Main Content

I am currently working on a personal project using an API built with Express and MongoDB. I’m planning to deploy it when I have finished.

So the thing is that I want to have many images for my entity Park or Rides to display them front side with carousels, cards components…

Do you have any ideas about the best practices? I don’t know if I have to store them in MongoDB, directly in my app or even using a S3 bucket with AWS.

2

Answers


  1. images are static assets used in an application and the size of high quality images can be heavy. I would personally recommend you using the Aws S3 because there are a couple of reasons.

    If you opt to store the images in a DB it will cost you a lot because you will have to convert the images in some binary form before storing in the db and then the server will be going to do all the processing before storing and after retreiving the image data from the DB which is not an efficient way where as on the other hand an Aws s3 bucket is quite cheaper and blazingly fast, and you can access the images through the s3 object url easily. Most of the unnessecary processing will be handled by the s3 like encryption and decryption and other security measures. On the other hand it is not a good option to keep assets directly in your app because the size of the images can get heavy and processing the images directly using the operating system is also not an efficient way to do it.

    Login or Signup to reply.
  2. There are a few ways to do it:

    1 – Not Recommended: Store in the project folder.

    It is not recommended store so many images here, because it can cause data leak and loss, the project folder becomes too large without needed and it doesn’t make much sense thinking about best practices.

    But, here is an example if you want to:

    Folder structure

    /public
        /images
            img_name.png
            img_name.png
            ...
    /src
    ...
    

    2 – Not Recommend: Store all images in Mongo DB.

    It’s not recommended because the database becomes too large and bulky, It also needs base64 convertion and Mongo DB file size limit is 16MB.

    If you want to, please, read the this.

    3 – Recommended: Store all images in cloud storage service, like Amazon S3, naming each one with your row id, for example:

    Database table:

    Users
    id - name - email - password
    1  - John - ...   - ...
    

    Image name:

    Using just row id = 1.png

    or concatenating with table name = user1.png

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search