question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onDownloadProgress has progressEvent.total property with zero value

See original GitHub issue

I’ve the simplest code like

onDownloadProgress: function(progressEvent) {
    console.log('download', progressEvent);
},

It returns object with total: 0 property.

Is there are any way to obtain total property with correct value?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:19
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

34reactions
tenbitscommented, Oct 19, 2018

Axios binds the onDownloadProgress function directly to native progress event of the xmlhttprequest instance: xhr.js#L145. The problem is in gzipped responses. Chrome for example has always for such responses lengthComputet=false and total=0. This makes also sens, as total reports the size of the content itself, and browsers can’t predict how many bytes will be the content. loaded reports the size after decoding, so even if you read the content-length header with

onDownloadProgress(event) {
  event.srcElement.getResponseHeader('content-length')
}

at some point you will get loaded > contentLength. A workaround would be to send the actual size in headers, smth. like X-Actual-Content-Length and then read the correct size in onDownloadProgress.

16reactions
qkdreyercommented, Oct 16, 2018

Ensure that your server is sending the Content-Length response header

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I get the onDownloadProgress percentage with axios ...
onDownloadProgress (progressEvent) { const percentage ... Simply the jsonplaceholder api doesn't have progress value for the get request .
Read more >
ProgressEvent.total - Web APIs | MDN
The ProgressEvent.total read-only property is an unsigned 64-bit integer value indicating the total size of the data being processed or ...
Read more >
Axios onDownloadProgress Example - CodeSandbox
CodeSandbox is an online editor tailored for web applications.
Read more >
此框架下axios onDownloadProgress 功能失效单页面正常#2512
onDownloadProgress has progressEvent.total property with zero value ` axios.get('https://32323233.oss-cn-beijing.aliyuncs.com/1.pdf', { onDownloadProgress: ...
Read more >
axios show download progress Code Example - Code Grepper
const config = { onUploadProgress: progressEvent ... //get use the onDownloadProgress, other requests use the onUploadProgress.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found