question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Progress bar for multiple file uploads

See original GitHub issue

Describe the issue

Basically, I want to upload multiple files at the same time, but, with a progress bar. With the current code I have (using onUploadProgress) it only works for the first file instead of with each file. Is there a good way to trigger onUploadProgress for each file instead of the first one?

I have been trying for hours and can’t seem to find a good solution.

Example Code

This is a snippet of the code I currently have.

let form_data = new FormData();

//Append image to the form data
form_data.append(
	"thumbnail",
	formState.thumbnail[0],
	formState.thumbnail[0].name
);

//Append all other files to the form data
for (let x = 0; x < formState.projectFiles.length; x++) {
	form_data.append(
		`projectFile${x}`,
		formState.projectFiles[x],
		formState.projectFiles[x].name
	);
}

//Set up the config
const config = {
	//Here is where I have the problem. This only works for the first file.
	onUploadProgress: function (progressEvent) {
		let percentCompleted = Math.round(
			(progressEvent.loaded * 100) / progressEvent.total
		);
		console.log(percentCompleted);
	},
	headers: {
		"Content-Type": "multipart/form-data"
	}
};

//Post the form data
axios
	.post("/api/catalog/submit/", form_data, config)
	.catch((err) => console.log(err));

Expected behavior, if applicable

I would like it to show upload progress (basically to trigger onUploadProgress) for every file that is being uploaded, not just the first one.

Environment

  • Axios Version 0.20.0
  • Adapter HTTP
  • Browser Firefox
  • Browser Version 80.0.1
  • Node.js Version 12.18.3
  • OS: Windows 10
  • Additional Library Versions React 16.13.1

Additional context/Screenshots

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:7

github_iconTop GitHub Comments

1reaction
siesta51commented, Mar 3, 2021

I had the same phenomenon. The progress bar will increase or decrease from the second upload. If you check progressEvent.loaded in console.log, it will increase or decrease. From here, it is a hypothesis, but when I checked the network of devtool of chrome, the first file upload had only one request, but the second file upload was divided into multiple requests. Since each of these divided requests is uploaded, I think that each progressEvent.loaded is being loaded. I wish I could converge the requests into one, but I don’t know how.

0reactions
Ibtesam-haider96commented, Jun 29, 2022

Any update on this issue? I am facing the same issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Managing Progress Bars for Multiple File Upload
So I am using a ajax to upload multiple files. Everything seems to be working like a charm... I just can't get to...
Read more >
JavaScript Multiple File Upload Progress bar with PHP
Vanilla JavaScript Multiple File Upload with Progress bar using Ajax with PHP. In this tutorial, we will show you how to upload multiple...
Read more >
React Multiple Files upload example with Progress Bar
In this React tutorial, I will show you way to build React Multiple Files upload example using Axios and Multipart File for making...
Read more >
Upload multiple files with HTML 5 and JavaScript ... - LinkedIn
A quick tutorial on how to use HTML 5 multiple file upload. ... Upload multiple files with HTML 5 and JavaScript (with Progress...
Read more >
File Upload Progress Bar with JS and PHP - CodeShack
In this tutorial, we'll be creating a multiple file upload interface with a progress bar using JavaScript (AJAX) and PHP.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found