-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Bug]: Example of upload file via Node is not working #926
Comments
Hello there, I could resolve this issue for you! |
Hello @brunomateus, and thank you for opening this issue. I'm sorry you are having trouble. Our team is indeed currently reworking the Upload documentation as it's not up-to-date with Strapi v4. That's so nice of you to offer some help @harris2310! ❤️ We really appreciate it! I'm assigning @StrapiShaun to this issue as he's in charge of the rewrite for this documentation, and I'll let him get in touch with you to solve this issue together. Thank you again! Edit: @gpene is actually the technical writer working on Upload docs, re-assigning the issue :-) |
@brunomateus Looks like this may have been addressed already just a few days after you reported the issue, if you could give it another go and confirm: https://github.com/strapi/documentation/pull/908/files |
Hi everyone, sorry for the late reply. I have just few notes:
|
Thanks for the additional notes @brunomateus - will keep those in mind as we revise the current documentation. |
Hi there, As I really need typescript for this project, I'm stuck. I've tried also sending a file like this: import { FormDataEncoder } from "form-data-encoder";
import { FormData } from "formdata-node";
import { fileFromPath } from "formdata-node/file-from-path";
import fetch from "node-fetch";
import { join } from "path";
import { Readable } from "stream";
// ...
export async function upload() {
// ...
const path2img = join(__dirname, "uploads", image.src);
const file = await fileFromPath(path2img);
const form = new FormData();
form.set("files", file);
const encoder = new FormDataEncoder(form);
const response = await fetch("http://127.0.0.1:1337/upload", {
method: "POST",
body: Readable.from(encoder),
headers: { Authorization: `Bearer ${process.env.STRAPI_API_TOKEN}` },
});
// ...
} And I'm getting a 400 error: I've checked my It's been hours I'm stuck with this and none of the solutions I've found on internet seem to work :'( |
@gpene could you reopen this thread please? The issue has never been solved. But when intercepting the request with mitmproxy, I can see the octet-stream of my file under the name "files". |
Hi @nagman. "gpene" is not working for Strapi anymore. I'll check with Strapi engineers what we can do for this one. |
Hi, |
I managed to fix it by:
|
Link to the documentation page or resource
https://docs.strapi.io/developer-docs/latest/plugins/upload.html#upload-files
Describe the bug
The sample of Node.Js code showed on that page is not working. It's always give you HTTP 400 and this messages "message":"Files are empty".
I spent long hours trying, then I decide to write something similar in Python and that's it, it worked at the first time.
Additional context
No response
Suggested improvements or fixes
I am not sure what is the current bug, it seems that form.append('files', file) is not working, but we need to fix that.
Also, I do believe that an example of code using entity or service API would be a great help. This is really useful when we need do populate a database.
Related issue(s)/PR(s)
No response
The text was updated successfully, but these errors were encountered: