github elbywan/wretch 3.0.4

10 hours ago

3.0.4 (2025-11-26)

🐛 Bug fix(es)

  • Improve body size computation when tracking upload progress (bfae158), closes #284
import wretch from "wretch"
import FormDataAddon from "wretch/addons/formData"
import ProgressAddon from "wretch/addons/progress"

const testString = Array(1_000).fill("This is a test string.")
const file = new File(testString, "test.txt", { type: "text/plain" })

wretch("https://httpbingo.org/post")
  .addon([ProgressAddon(), FormDataAddon])
  .formData({
    "textfile": file,
  })
  .onUpload((loaded, total) => {
    console.log(`Uploaded ${loaded} of ${total}`)
  })
  .post()
  .res(res => console.log(res.status))
  .catch(console.error)
# "total" is now correctly inferred:
Uploaded 0 of 22174
Uploaded 134 of 22174
Uploaded 156 of 22174
Uploaded 178 of 22174
Uploaded 200 of 22174
Uploaded 222 of 22174
# (…)
Uploaded 22090 of 22174
Uploaded 22112 of 22174
Uploaded 22134 of 22174
Uploaded 22136 of 22174
Uploaded 22174 of 22174
200

⬆️ Version update(s)

Don't miss a new wretch release

NewReleases is sending notifications on new releases.