-
-
Notifications
You must be signed in to change notification settings - Fork 683
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
ContentType: text/plain not showing in fields #875
Comments
If I understand correctly you want to access files sent as text/plain as if it was another field ? |
This line in the code separates fields from files: So if you don't have a mimetype it will appear as a field |
Yes, i managed to do it in an ugly way around for (let [fileField, filesArray] of Object.entries(files)) {
const file = (filesArray as File[])[0];
switch (fileField) {
case "id":
id = await fileToString(file.filepath);
fs.rm(file.filepath);
break;
case "extraData":
extraData = JSON.parse(await fileToString(file.filepath));
fs.rm(file.filepath);
break;
default:
tile = file;
break;
}
} but i think as text/plain usually contain string, for disclaimer i cant really change how i receive data, and 'id','extradata' are bassically oneliners |
Do you suggest to change formidable ? |
@GrosSacASac I would like to see this change as well, I missed this issue but I commented about running into the same problem in #495 |
What exactly should change ? |
if mimetype is text/plain it should be decoded into fields instead of file with provided charset, unless explicity specified, |
not automatically, and not default behavior
yep, through option. |
Formidable v1 used to put "a" in
which sends:
Upgrading to Formidable v2 broke my app. NB: curl does not send "Content-Type" for non-files. |
Workaround tested on v2:
|
I have the same issue. My user is calling my API with a C# client. Their multipart/form implemtation always adds the I think this should be fixed upstream in this library, no? |
That's why we even expose internals and allow overriding, so it can be extended. ;) Converting text/plain to fields by passing some option, could be a good feature too.
Really strange.. :D Never noticed that, or I forgot it. |
I can confirm that there's no way to succesfully get |
So, the code used to look at the existence of a filename and would consider it a field if a file name did not exist. I've been tracing back the code and it used to be what I would consider correct: formidable/src/incoming_form.js Line 195 in 15f174f
But then was changed to look at mime type here: 621e72a I'm not really sure what the change fixed, but it's not correct. A field is a file if it contains a filename. Otherwise, it's a field. Right?? |
As of now only workaround by @prigaux is working, Is there any fix in library? I am using Retrofit as client in Android app. |
I am using this code:
After add 'onPart' function, the uploaded file can not open any more; |
Support plan
Context
What are you trying to achieve or the steps to reproduce?
Im trying to make custom server functionality on nextjs api route,
where i get some request data from game as "multipart/form-data;"
but some of the data has "text/plain" content type.
What was the result you got?
Only the files variable gets populated.
As i needed to disable parser for nextjs
i cant really use req.body.
looping for 'text/plain' mimetype in files and parsing them manualy is not desired either
What result did you expect?
'text/plain' content type parsed into fields variable
The text was updated successfully, but these errors were encountered: