Reputation:
I'm trying to run a background task runner on the Django web server. I'm not that familiar with Django but I've done this with asp.net before. So essentially I have the html and JS send a post, which will be a file, usually a huge file, then Django will send back a hash for which to check the status of the file upload. The website will then have a processing bar that tells the user what percent is uploaded or if it has crashed. Is there a way to do this in Django? In C# there's things called delegates for this, where you can just check the status of the job, but the web server still receives requests, cause I want to site to keep pinging the server to get the status.
Upvotes: 1
Views: 390
Reputation: 15421
You can read here in more detail how to handle file uploads in Django. A common way you might handle an uploaded file is
def handle_uploaded_file(f):
with open('some/file/name.txt', 'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)
Looping over UploadedFile.chunks() instead of using read() ensures that large files don’t overwhelm your system’s memory.
There are a few other methods and attributes available on UploadedFile objects; see UploadedFile for a complete reference.
Depending on how big it is you might need to change FILE_UPLOAD_MAX_MEMORY_SIZE.
Upvotes: 1