To add upload progress indicators for fetch with JavaScript, we use axios.
For instance, we write
const { data } = await axios.request({
method: "post",
url: "/example",
data: myData,
onUploadProgress: (p) => {
console.log(p);
},
});
to call axios.request to make a post request by calling it with an object with method set to 'post'.
We make a request to the '/example' URL.
We set onUploadProgress to a function that logs progress p.