X
X
Xymis2020-12-19 14:29:28
Django
Xymis, 2020-12-19 14:29:28

What is the best way to store images in a database (base64 or locatino/img.png)?

Now I am modeling a database, for the first time in a pet project I use the ability to upload images by the user.
There was a question of a choice of storage of images.
Which option to choose?
1. base64 string in the database, then there will be a heavyweight database, but calculations will be only on the front
2. image location, but then in addition to calculations on the front there will be calculations on the backend (get the string, convert it to an image and save it to a folder, save the directory to the database) and on the output (take the location from the database, convert the image to base64, send the string to the front), and the directory will be too heavy.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dr. Bacon, 2020-12-19
@bacon

If you do not know how, then definitely - ImageField, you have Django.
If you want to store all these in the database (which means you understand exactly why), then why are there any intermediate base64-type formats to take up more space? Store in binary, but once again, this is only if you can clearly explain why in the database.

Вот так например https://www.regex101.com/r/BEn6W7/1

M
Mikhail Osher, 2017-01-27
@miraage

"SIP/rosnet_6651560/808080808080,300,Tt".split('/').pop().split(',')[0]

C
Catrinblaidd, 2017-01-29
@Catrinblaidd

$string = "SIP/rosnet_6651560/808080808080,300,Tt";
\preg_match('/\/([\d]+)\,/', $string, $result);
echo $result[1];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question