user2092743
user2092743

Reputation: 381

How to download an image from Django

I build a django application that generates an image and places it in a folder on the server. I want to download that image, located on the server at example.com/generatedimages. How do I send this image to the client? What does it have to do with static files? Do I need to generate a URL for that image temporarily? I do not use Django templating.

Technical information:

Thanks in advance.

Upvotes: 0

Views: 1433

Answers (1)

Bruce
Bruce

Reputation: 1380

If the file is placed in settings.MEDIA_ROOT then it is publicly available and you can use settings.MEDIA_URL to create a link.

If the file is outside of settings.MEDIA_ROOT, you can use built-in view django.views.static.serve.

If you need some protection, just use standard view but return FileResponse.

Serving large files through Django is not efficient. If you need large files, check django-sendfile.

Upvotes: 1

Related Questions