-
Notifications
You must be signed in to change notification settings - Fork 282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FormData.hasKnownLength always returns true #399
Comments
Do you mind to elaborate on how it break node-fetch? |
Try this: const fetch = require('node-fetch')
const FormData = require('form-data')
const { Readable } = require('stream')
let i = 0
const stream = new Readable({
read(size) {
i++
this.push(i <= 16 ? Buffer.alloc(size) : null) // Buffer full of 0's
}
})
const apiUrl = 'https://bayfiles.com/api/upload'
const form = new FormData()
form.on('data', buf => console.log(buf.length, buf))
// form.hasKnownLength = () => false
console.log(`Form has known length: ${form.hasKnownLength()}`)
form.append('file', stream, 'myFile')
fetch(apiUrl, {
method: 'POST',
body: form
})
.then(res => res.text())
.then(json => {
console.log(json)
}) FormData says the stream has a known length even though it hasn't. Then try uncommenting |
any update on that? |
I believe that |
This function is needed for |
@SkyBeastMC I don't know the details to be honest, but even when that is the case, it is leaking abstractions. It is fine if But if you have to expose a function for that,
So probably things need to be clean up. Just a feedback. |
I believe the offending line is https://github.com/form-data/form-data/blob/master/lib/form_data.js#L104 . When body.path == undefined
value.readable == true
value.hasOwnProperty('httpVersion') == false The |
I spent a fair bit of time troubleshooting a similar issue, the PR #382 solved the issue for me. |
FormData.hasKnownLength() returns true whether my form data has a known length or not (ie. inserting a stream)
This break node-fetch, because they use the known length to send Content-Length header.
The text was updated successfully, but these errors were encountered: