How to add upload progress indicators for fetch with JavaScript?

Spread the love

Sometimes, we want to add upload progress indicators for fetch with JavaScript.

In this article, we’ll look at how to add upload progress indicators for fetch with JavaScript.

How to add upload progress indicators for fetch with JavaScript?

To add upload progress indicators for fetch with JavaScript, we use axios.

For instance, we write

const response = await axios.request({
  method: "post",
  url: "/foo/bar",
  data: myData,
  onUploadProgress: (p) => {
    console.log(p);
  },
});

to make a post request with axios.request.

We set onUploadProgress to a function that gets the request progress p.

Conclusion

To add upload progress indicators for fetch with JavaScript, we use axios.

Leave a Reply

Your email address will not be published.