Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynchronous processing of file upload in Django

Tags:

django

upload

When you upload file with Django, the response won't be returned until the file upload has completed. If the uploaded file is large, it will take a long time, during which the user can't do anything but wait. Is there any way to implement asynchronous processing of file uploading? So, when a file is uploading backend, the user can do some other operation on the current page without interrupting the upload?

like image 823
user1567395 Avatar asked Aug 01 '12 03:08

user1567395


People also ask

Does Django support asynchronous?

Django has support for writing asynchronous (“async”) views, along with an entirely async-enabled request stack if you are running under ASGI. Async views will still work under WSGI, but with performance penalties, and without the ability to have efficient long-running requests.

Does Python Django support multiple file upload?

The Django documentation for File Uploads, gives a brief understanding of the workflow of how to upload a single file using forms and importing in views. In a similar way, we can also tweak it to upload multiple files using forms and views.

What is asynchronous task in Django?

An async view function in Django is detected by the annotation async def , which then runs the async view in a thread within its own event loop. This gives the benefit of being able to do and run tasks concurrently inside the async views.

How do I import files into Django?

Django provides built-in library and methods that help to upload a file to the server. The forms. FileField() method is used to create a file input and submit the file to the server. While working with files, make sure the HTML form tag contains enctype="multipart/form-data" property.


1 Answers

I am aware that it has been more that 5 years since this question was asked but I have similar problem and there are no "simple answers" on SO.

For your problem I may suggest using a progress bar (if using Django forms). Uploading a file asynchronously might not be possible in Django.

In my case the browser element is not crucial and I am considering moving the file upload from browser upload to some sort of FTP / AWS S3 file storage and working on this.

like image 86
mpiskore Avatar answered Jan 03 '23 22:01

mpiskore