N
N
Nikita Neskuchaev2018-04-17 19:52:00
Node.js
Nikita Neskuchaev, 2018-04-17 19:52:00

How to properly store user avatars in node.js?

With the help of express, an avatar upload system was implemented. Where should I push the avatar file next? To a folder on the backend?
And how to give this file to the user if he requests it in his profile?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexalexes, 2018-04-17
@alexalexes

https://habrahabr.ru/post/37686/
Here for PHP, but for any backend the concept will not change from this.
1) We redirect all links for getting pictures to a script for checking access rights.
2) We check the user's access rights according to the session data;
3) Everything is OK, the user session is alive, the file exists, the user is the owner of the file or somehow relates to it (at least for reading) - we send the command to the nginx server to give the file from the protected directory.
4) Not OK, we give the user 404.
3.1) No nginx ? We read the file with a server script (preferably in small portions, to save server RAM), give the user data with the corresponding mime type. On the client side, the given data will be drawn in the img tag or in the background-e of the DOM element, no matter how the binary resources arrived from the server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question