question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mimetype Parsing for Non-File Parts in MultipartForm

See original GitHub issue

Support plan

  • Which support plan is this issue covered by? (Community, Sponsor, Enterprise): Community
  • Currently blocking your project/work? (yes/no): No, but v1 didn’t have this issue at the time, only when I updated did this fail
  • Affecting a production system? (yes/no): Yes

Context

  • Node.js version: v16.13.1
  • Release Line of Formidable (Legacy, Current, Next): Current & Next
  • Formidable exact version: v2.0.1, also tried latest v3
  • Environment (node, browser, native, OS): Node on Windows & Linux
  • Used with (popular names of modules): NextJS

What are you trying to achieve or the steps to reproduce?

When I use the C# methods to generate a MultipartFormDataContent object, passing in a StringContent object includes a mimetype (Content-Type) for that header.

Based on formidible, it assumes any part with a mimetype is a file, which doesn’t seem to be the case for some core libraries (according to Microsoft’s implementation).

I’m not entirely sure which is the expected and correct implementation based on the RFC (sorry, not enough time to research this myself). I was wondering, back in v1 before I upgraded to v2, this seemed to have been accounted for and so I wonder if this upgrade introduced a bug?

What was the result you got?

Using form.parse, err was empty, fields was not populated, and files had 2 entries, one which was the file and one which was a string with a mimetype of text/plain; charset=utf-8. When I removed the header from the string part manually in the client, fields was populated as expected (1 entry) and so was files (also 1 entry).

What result did you expect?

It should maybe be smarter in recognizing the mimetype, or maybe outlining in the documentation that the mimetype should be null for non-file parts. Or maybe, Microsoft is the one in the wrong and there is no action to be performed 😃

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
tunnckoCorecommented, Jan 17, 2022

Yea, in v1 it was part.filename == '', then i tried to shorten it and make some more sense or refactor, and changed it to !part.filename then some weird bugs appear and failing tests. So i thought… okay, in the general case, fields “don’t have” mimetype and if there is it most probably is file and that’s the expected.

So… yea, that was the case. Good adding it to the changelog, we probably missed a lot of things in the long process. Thank god we published it as v2, so it’s acceptable there can be breaking changes, haha.

@GrosSacASac great, we may add it to the readme docs somewhere too?

1reaction
GrosSacASaccommented, Jan 1, 2022

Files is more a concept than a thing on the web platform. What you do with the incoming data is up to you. You could, after form.parse handle files with text/plain like fields.


this is how we think it is a field if (!part.mimetype) {

and this is how it was done in 1.2.6 if (part.filename === undefined)

In the usual case a file has both filename and mimetype when upload through a regular web html form.


Should we change something ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

RFC1341(MIME) : 7 The Multipart content type
The multipart delimiters and header fields are always 7-bit ASCII in any case, and data within the body parts can be encoded on...
Read more >
MIME types (IANA media types) - HTTP - MDN Web Docs
MIME types are case-insensitive but are traditionally written in lowercase. The parameter values can be case-sensitive.
Read more >
mime/multipart - Go Packages
ReadForm parses an entire multipart message whose parts have a Content-Disposition of "form-data". It stores up to maxMemory bytes + 10MB (reserved for...
Read more >
Multipart Requests in Go - The Code Library
We will first have to parse the content-type header to determine if the request is actually a multipart message. We can do this...
Read more >
Chapter 23. Multipart Providers - JBoss.org
The multipart mime format is used to pass lists of content bodies. Multiple content bodies are embedded in one message. "multipart/form-data" is often...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found