-
-
Notifications
You must be signed in to change notification settings - Fork 102
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Request fails while using fs.createReadStream
#138
Comments
FormData length needs to be calculated and the formdata specification can't do that using a readable stream. what you can do instead is to import // 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";
async function predictUsingFile(filePath) {
// const fileStream = fileFromSync(filePath);
const file = fileFromSync(filePath); // this will only stat the file for getting the file size
const formData = new FormData();
formData.append("file", file);
formData.append("modelId", this.modelId);
const response = await fetch(
`https://app.nanonets.com/api/v2/ImageCategorization/LabelFile`,
{
method: "POST",
headers: {
"Authorization": this.authHeaderVal,
"Accept": "application/json"
},
body: formData
}
);
return response.json();
} |
fyi: NodeJS already have a Blob class, but it's pretty useless as of now.... unless we are able to get a file backed up by the filesystem then it has no useful benefits. They want to change this so they can implement a FormData among other things. Give this issues a 👍 if you want to see it prioritized :) |
there is also a 2nd way to append files and avoid using fetch-blob, they just need to look like a file or blob fd.append('name', {
[Symbol.toStringTag]: 'File'
size: 123,
name: 'foo.txt',
stream() {
return readableStream
}
}) |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
The code below works with the
form-data
package, but not with this package. I cannot figure out why. Can anyone please help?Code
Error response
The text was updated successfully, but these errors were encountered: