File Uploading Progress in Javascript Fetch

Published on May 17, 2020

Currently it is not possible to get file upload progress for fetch() method.

However going by chromeststatus, it is currently in active development. Probably it may be available within a few months.

Upload progress in fetch() is going to be possible by using a ReadableStream body.

Solution for Now ?

Till the time upload progress is enabled for fetch(), XMLHttpRequest object can be used to get file uploading progress.

<input type="file" id="file-input" />
let data = new FormData();
data.append('file', document.querySelector('#file-input').files[0]);

let request = new XMLHttpRequest();'POST', '/upload'); 

// upload progress event
request.upload.addEventListener('progress', function(e) {
	// upload progress as percentage
	let percent_completed = (e.loaded /*100;

// request finished event
request.addEventListener('load', function(e) {
	// HTTP status message (200, 404 etc)

	// request.response holds response from the server

// send POST request to server
In this Tutorial