-
Notifications
You must be signed in to change notification settings - Fork 31
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
Doesn't work either with latest stable and beta version of node-fetch #94
Comments
Historically blob have always lowercased the type both in the constructor and in the (i know buffer.Blob in node v15.7 and up also lowercase the blob.type - i have already warn them about this and said it might not be such a good idea to do it and fetch-blob was thinking about removing this casting to lowercase) Like you i also had this exact same issue 3years ago that i fixed by making the boundary only lowercased jimmywarting/FormData#17 looking at your code you also use uppercase characters - `FormDataBoundary${randomBytes(16).toString("hex")}`
+ `formdata-boundary${randomBytes(16).toString("hex")}` If the users have a option to define there own boundary in the encoder constructor then i think that you should lowercase the boundary before it starts encoding constructor(form: FormDataLike, boundary: string = createBoundary()) {
if (!isFormData(form)) {
throw new TypeError("Expected first argument to be a FormData instance.")
}
if (typeof boundary !== "string") {
throw new TypeError("Expected boundary to be a string.")
}
- this.boundary = boundary
+ this.boundary = boundary.toLowerCase() cuz they might use buffer.Blob or some other that also lowercase the type I reported this lowercasing issue at whatwg/html#6251 in late 2020 and they seems to agree that lowercasing the blob's type isn't that good as you loose the parameters "real" values in the I stripped this lowercase casting out of could you try if this works code works with fetch-blob@3.0.0-rc.0 ? import {FormData} from 'formdata-node'
import {Encoder} from 'form-data-encoder'
import Blob from "fetch-blob"
const encoder = new Encoder(new FormData())
const type = encoder.contentType
console.assert(new Blob([], { type }).type === type, "type stays the same")
console.assert(new Blob([], { type: 'foo/bar; key=VALUE' }).type === 'foo/bar; key=VALUE', "type stays the same") |
form-data-encoder allows you to set your own boundary string as the second parameter in constructor. Tried this with |
Maybe I will do it to fix possible issues, or maybe I'll just recommend to do so if anybody runs into the same problem with this example. |
Tested this with v3 – the |
blob#stream is iterable. Like i mention earlier, you may have a problem with checking if it's a buffer instead of uint8array |
No, it's just me misspelled fetch-blob with node-fetch. I meant that node-fetch does not support Symbol.asyncIterator as request body yet. And as you can see in the top of this thread, node-fetch is trying to call |
@jimmywarting As I mentioned here, I'm running into the problem when using this package with node-fetch. The problem remains both in the latest stable and beta. With
fetch-blob@3.0.0-rc.0
andfetch-blob@2.1.1
.I was trying to test an example for my
form-data-encoder
where the encoder targetingBlob
as you did in formdata-polyfill:When I run this code
node test.mjs
this happens:body.stream().pipe(dest);
. This error appears innode-fetch/src/body.js:374:17
fetch-blob@2.1.1
it will lowercase the value ofBlob#type
which breaks boundary string returned by form-data-encoder.The text was updated successfully, but these errors were encountered: