Is it possible to store images as BLOB in MySQL database using Django models?

I want to store images in MySQL Database (not the path, the actual image) using Django as the backend and React js as the frontend. Is it possible to do that?

Please help me in resolving this issue. Thanks in advance.

Yes, it’s definitely possible to do that.

And, if you want to store the images as base64 data, you can return it “in line” in your html response, avoiding the need for the extra http requests to retrieve those images.

As one example, see Django: How to send image file as part of response - DEV Community


I have been doing this for a while without issues.

A couple things I’m concerned with but haven’t really had to the time to look into:

  • row size in the db. A long time ago I remember having encountered an error that was straight from the db and was about the text length of a field exceeding some limit. Never happened again since. I imagine too many images in a text field could lead to that?

  • fetch time. DBMS’s aren’t probably made to be used like mass storage devices, so is fetching a very large text (the encoded image) going to be as efficient as it would be when getting it from the filesystem?

Just a couple of thoughts

1 Like