I am looking to implement a progress bar for both uploads and downloads. I have been searching for solutions for the past few days and there are a lot out there. Some suggest using celery and some type of message broker, and then there are some solutions using pure JavaScript.
For the download option, I can get the exact # of files that I need to download, so it would be fine if I could implement a % of the total files. For example, I have 10 files to download so after each file is downloaded, I increase the progress bar by 10%.
For file uploads, the user can select a single file or they can upload all files in a folder (eventually, I will allow them to drag/drop to a list to be uploaded). So for the single file upload, I’d like to be able to report the percentage of the file that is being uploaded, and for the multiple file upload, possibly using the same technique as the multi-file download, assuming I know how many files the user has selected.
Right now, I am leaning toward the JavaScript option as there would be fewer library dependencies, but I’m trying to get some opinions on this. What is the better or preferred way to handle this, and where can I find a good example/tutorial on how to do this. I have watched several videos on both methods, but am still having trouble seeing how to implement this in my project.
If you have opinions and some suggestions for good tutorials, please send them along.
This depends upon how you’re handling the file transfers in Django. But in general, there’s always going to be some JavaScript involved.
If the uploads are being done through a regular Django form where the files are submitted via POST request, then this would need to be done in JavaScript - Django doesn’t “see” any of the posted data until all of it has been received by the server.
If you are submitting these through AJAX-style requests or websocket transmissions, you could handle this either way, provided your client library sends that information to the server first - but either way, there will be some JavaScript involved.
It’s a similar situation for the downloads, except the HTTP protocol does not support downloading multiple files over a single request. This means that downloading multiple files either requires JavaScript to issue individual requests for the files, or for Django to bundle those files for transmission.
Thanks Ken. I’m fairly comfortable with JavaScript, so I expect that will be part of the solution. I’m also assuming for this to work, I need to use AJAX.
As for the downloads, they are actually downloaded from Dropbox one-at-a-time in the view, so this is a similar situation to the upload. I could use the file of files method to set the percentage complete. I mainly want to give the user some feedback that something is happening.
I’ll look into some JavaScript and AJAX solutions for this unless you know of any specific examples that are worth looking at.