Skip to content

Request fails while using fs.createReadStream #139

Answered by jimmywarting
HarshKapadia2 asked this question in Q&A
Discussion options

You must be logged in to vote

FormData length needs to be calculated and the formdata specification can't do that using a readable stream.
this is what have made form-data so complicated to use. it's only suppose to accept strings, blobs & files. (this blobs have a size property that can be read without reading everything into memory before posting it)

what you can do instead is to import fetch-blob that we use internally and do something like this:

// import FormData from "form-data"; // Works with this
import { FormData } from "formdata-polyfill/esm.min.js"; // Does not work with this
import { fileFromSync } from "fetch-blob/from.js";
import fetch from "node-fetch"; // v3
// import { createReadStream } from "fs";

a…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by jimmywarting
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #138 on November 12, 2021 09:24.