skip to Main Content

Currently, I’m working on a website project where I plan to feature two types of images: one for profile pictures (one-to-one with user profiles) and another for item images, which could include multiple images per item.

I’m using Spring Boot to communicate with MySQL for storing all the item-related data like names, descriptions, and so on. My question is: What would be the best way to store these images?

Should I store the images directly in MySQL, or is there a better solution? I’m curious whether storing images in the database is efficient or worth it.

I’ve been reading about something called BLOB (Binary Large Object), which seems like it could solve my issue. From what I understand, it allows you to store images directly in the database. However, I’d love to hear your opinion.

Or should i just store it somewhere else?

2

Answers


  1. storing images in BLOB is possible but may not be the best option, because it will slow down the database performance, also you may encounter issues when trying to backup or restore the database due to its increasing size
    I would recommend using cloud storage like S3, they usually provide some more options that can help you serve the images to the client, and resize the images…
    local storage is also an option but may not be efficient in a cloud environment

    Login or Signup to reply.
  2. I’ve recently had this same dilema.
    your choices are to store in the database, or to store in a file system.

    database

    pros

    • easy to manage in terms of porting data from one env to another (this can be negatively affected by the size of the data over time)
    • easy to avoid ophaned images (using cascade delete and table relationships)
    • easier to manage in terms of programming – just get the image from the database along with other data.

    cons

    • significant increase in database size (may impact backup, migrations, cost)

    file system

    pros

    • regular files easy to open and inspect
    • easy to store on most any file system (nothing specail needed)

    cons

    • need to think carefully about file structure and file names so you can remove ophaned images when accounts are deleted etc.
    • need to secure the folder so images cannot be accessed directly by a link.
    • need to track and store image file names in the database and all the headache that goes with that in terms of not ending up with a bunch of images in a folder that you have no idea if you need anymore.

    for me I went with the Database option.

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