Skip to content

uploadProgress for non-stream bodies #1735

@Vivalize

Description

@Vivalize

Describe the bug

I'm sending a POST request to a server with a large string as the body, and would like to get granular progress events as it sends. However, the on('uploadProgress') listener only seems to fire at the start and end of the request, and never mid-transit. I got the impression from #322 that a workaround was implemented to make this work, but I can't seem to achieve this. If something else is needed from my code to make it work, it would be nice to see more clarification in the documentation.

  • Node.js version: v14.17.0
  • OS & version: macOS Big Sur 11.2.3

Actual behavior

{ percent: 0, transferred: 0, total: 10000000 }
{ percent: 1, transferred: 10000000, total: 10000000 }

Expected behavior

{ percent: 0, transferred: 0, total: 10000000 }
{ percent: 0.1, transferred: 1000000, total: 10000000 }
{ percent: 0.2, transferred: 2000000, total: 10000000 }
...
{ percent: 0.8, transferred: 8000000, total: 10000000 }
{ percent: 0.9, transferred: 9000000, total: 10000000 }
{ percent: 1, transferred: 10000000, total: 10000000 }

Code to reproduce

const got = require('got')

// This is a barebones http server to reproduce realistic round-trip request times
const server = 'https://got-progress-test.herokuapp.com/'

// Generate a random string to simulate a large request body size
const randomString = Array.from({length: 10000000}, () => String.fromCharCode(Math.floor(Math.random() * 57 + 65))).join('')

// Send the string as the body of a post request
got.post(server, { body: randomString })
    .on('uploadProgress', progress => console.log(progress))

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationThe issue will improve the docswontfixThe issue cannot be fixed on Got side

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions