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.

TypeError: Could not parse content as FormData.

See original GitHub issue

What version of Remix are you using?

1.5.1

Steps to Reproduce

1.5.1 introduces breaking change on how unstable_parseMultipartFormData works.

https://github.com/remix-run/remix/commit/25b4c83b10c5bc4d84ea81407e7de1a0e4f43df4#diff-70aea120272f0e47c3bc1e93fd83fadb9997e605479b1f3cc0afbafc58efe563R42

Before 1.5.1 unstable_parseMultipartFormData wouldn’t care if your form had enctype="multipart/form-data", but now there is a check that throws TypeError: Could not parse content as FormData..

To fix it make sure you include the enctype in your forms.


Also you need to update your uploadHandler to include memory upload handler. Something like this:

export const uploadHandler = unstable_composeUploadHandlers(
  unstable_createFileUploadHandler({
    avoidFileConflicts: true,
    directory: '/tmp',
    file: ({filename}) => filename,
    maxPartSize: 5_000_000,
  }),
  unstable_createMemoryUploadHandler(),
);

I know these are unstable APIs, but if the team could point out the breaking changes next time in the release notes that would be great.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:7
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
ScottAgirscommented, Jun 18, 2022

To fix it make sure you include the enctype in your forms.

Thanks for the tip, just wanted to mention for future reference that it’s encType="multipart/form-data" with capital T in React

<form
  action={`/new`}
  method="POST"
  encType="multipart/form-data"
>

Thanks, @CanRau, this solved issue for me. Perhaps there’s some way to add this to Remix linter?

3reactions
ivosabevcommented, May 24, 2022

@LukasCornille, look at my comment on composing the handlers. The uploadHandler only handles the file part of the formData, you need the memoryUploadHandler to parse the POST fields.

export const uploadHandler = unstable_composeUploadHandlers(
  unstable_createFileUploadHandler({
    avoidFileConflicts: true,
    directory: '/tmp',
    file: ({filename}) => filename,
    maxPartSize: 5_000_000,
  }),
  unstable_createMemoryUploadHandler(),
);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not parse content as FormData. ...
I have a simple python server that is sending a multipart response to a javascript client, but I get this error TypeError: Could...
Read more >
multipart/form-data fetch cannot be parsed with Response. ...
formData method on the result, yielding "TypeError: Could not parse content as FormData.". Expected results: One should be able to use the .formData...
Read more >
Wink error parsing multipart form-data with ...
If I include the content-type: multipart/form-data I get this: "Error 500: ... I did find this https://issues.apache.org/jira/browse/WINK-371 but is this ...
Read more >
Could not parse request with message: Missing boundary ...
For requests with Content-Type “multipart/form-data” the body of the requests must be structured according to the rules of that content type.
Read more >
Solved: application/x-www-form-urlencoded content type err...
Then this part of the content cannot be used in Parse JSON, because its type is clearly application / x-www-form-urlencoded and not JSON....
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