Categories
JavaScript Answers

How to add upload progress indicators for fetch with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *