Is there any way to return the downloaded files to the user?

Is there a way to display images submitted by users on the displayed page? I read this page about downloading files, but the only way to send it back is with help send_file/5that doesn't seem suitable for the images displayed on the web page. I thought to move the file to a folder assets/static, but I don’t feel that this is where it belongs.

I come from the world of Django, and there was a separation between static files and uploaded content, and I was interested, and in phoenix there was a similar concept.

So how can I make an image uploaded by the user?

+4
source share
1 answer

There are two options. You can use base64 for the image and use the embedded uri data ( https://en.wikipedia.org/wiki/Data_URI_scheme ) right in your view. This greatly inflates your image size and is best suited for small images, where the cost of an extra return flight to the server is more than the cost of sending a 33% increase in inflation. You also do not get any benefits when caching, and reusing the image will result in multiple copies.

. content-type (, image/png), send_file/5. <img> src. , .

, nginx X-Accel (https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/), , nginx . - , URL.

. Erlang VM IO.

+2

Source: https://habr.com/ru/post/1629658/


All Articles