H
H
Hellas2017-10-10 15:18:21
Images
Hellas, 2017-10-10 15:18:21

What is the best way to store images on the server?

For example, users have the ability to upload avatars for themselves.
- what is the best way to store these images: in the uploads folder for each user id (/uploads/1/avatar.png) or all avatars in one folder in md5. Maybe base64 in the database?
- what to do with the size of images if the blocks for these images do not have a fixed size (they change depending on the size of the user's screen)?
Is it worth trying to achieve the perfect result so that the image is always adjusted to fit the block size?
59dcb9e4db23b291024670.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima Pautov, 2017-10-10
@Hellas

in base64, I would not store. The response from the server will weigh a lot if there are a lot of pictures. I once tried this. Everything becomes much easier. Converted to the database in the browser. But if you need to get a list of products, for example 50, and all pictures in base64, then the response from the server will be huge.
It is better to store the path to this folder in the database. Everything as usual. And so it had to be done.
It is easier to insert a picture as a background if they are all different and apply background-size: cover; So many do. For example, everyone's favorite vk does exactly the same with all images. Just limit the image size and that's it.
Or, already on the server, crop the picture for the desired section. It's worse, because you will need to store these cropped pictures somewhere. I like the background

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question