Send image as attachment in browser

I have a static folder managed by apache where images are stored. I wonder if this is possible by setting apache to send all files from this folder as downloadable files without opening them as images inside the browser? I believe I can do this by creating a special look in Flask, but I think it would be better if I could do this with a simpler solution.

+4
source share
2 answers

flask.send_from_directory with as_attachment=True argument can do this.

Alternatively, you can configure Apache to send the Content-Disposition: attachment header, as in this answer

+3
source

You can force the content to be a downloadable attachment using http headers.

In PHP, that will be:

$ fileName = 'dummy.jpg';

header ("Content-Disposition: attachment; filename = $ fileName");

The script then flushes the original contents of the file.

+1
source

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


All Articles