PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, October 13, 2022

[FIXED] How can I get the onDownloadProgress percentage with axios get method?

 October 13, 2022     axios, javascript, reactjs     No comments   

Issue

Here is my code :

React.useEffect(() => {
        axios
            .get('https://jsonplaceholder.typicode.com/photos', {
                onDownloadProgress: (progressEvent) => {
                    let percentCompleted = Math.round(progressEvent.loaded * 100 / progressEvent.total);
                    console.log(progressEvent.lengthComputable);
                    console.log(percentCompleted);
                }
            })
            .then((response) => {
                console.log('response done');
            })
            .catch((error) => {
                console.log(error.message);
            });
    }, []);

And this is the console.log :

false
Infinity
false
Infinity
response done

I get infinity while trying to get the get method progress event . How can I get the exact percentage for the axios get method ?


Solution

I solved the issue by using another api for get request . Simply the jsonplaceholder api doesn't have progress value for the get request .

axios.get('https://systran-systran-platform-for-language-processing-v1.p.rapidapi.com/translation/text/translate',
 { onDownloadProgress: (progressEvent) => {

     let percentCompleted = Math.round(progressEvent.loaded * 100 / 
     progressEvent.total);
     console.log(progressEvent.lengthComputable);
     console.log(percentCompleted);

  }
})


Answered By - Mehdi Faraji
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing