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.

submit multipart/form-data with empty file input, got error on request.formData()

See original GitHub issue

What version of Remix are you using?

1.6.1

Steps to Reproduce

Empty remix app with this route

import { ActionFunction } from '@remix-run/node';
import { useSubmit } from '@remix-run/react';
import { useRef } from 'react';

export let action: ActionFunction = async ({ request }) => {
  const fdata = await request.formData();
  console.log(fdata);
  return null;
};

const Comp = () => {
  const submit = useSubmit();
  const formRef = useRef<any>();

  return (
    <>
      <form ref={formRef}>
        <input type="file" name="test" />
      </form>
      <button
        onClick={() => {
          submit(formRef.current, {
            method: 'post',
            encType: 'multipart/form-data',
          });
        }}>
        CLICK SEND WITHOUT FILE. BOOM!
      </button>
    </>
  );
};

export default Comp;

Clic the button without any file.

Got this error on the server:

TypeError: filename is only supported when value is Blob or File

Expected Behavior

Simply work.

Actual Behavior

Gives error.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
cwohlmancommented, Jun 28, 2022

I think I have a fix for this in https://github.com/remix-run/web-std-io/pull/12 but wasn’t able to test it as I don’t have my environment fully set up.

3reactions
machourcommented, Aug 2, 2022

@mcansh seems to be working fine now 🎉

🍺  ~/test-3570 $ yarn dev
yarn run v1.22.19
$ remix dev
Watching Remix app in development mode...
💿 Built in 197ms
Remix App Server started at http://localhost:3000 (http://192.168.1.5:3000)
GET / 200 - - 23.356 ms
FormData {}
POST /?index=&_data=routes%2Findex 200 - - 14.282 ms
FormData {}
POST /?index=&_data=routes%2Findex 200 - - 6.654 ms
FormData {}
Read more comments on GitHub >

github_iconTop Results From Across the Web

AJAX request fails when sending FormData() including empty ...
If not file is selected: The Ajax request runs for about 20 seconds (build in timeout?) and than returns with an empty sucess...
Read more >
[Multipart/form-data] Sending File to REST API returns Bad ...
So I'm sending an image file to a REST API using the multipart/form-data forge component and the response is bad request with the...
Read more >
FormData - The Modern JavaScript Tutorial
This chapter is about sending HTML forms: with or without files, with additional fields and so on. FormData objects can help with that....
Read more >
XMLHttpRequest cannot correctly send FormData - Browsers
Describes an issue in which XMLHttpRequest cannot correctly send FormData containing empty file elements in Microsoft Edge for Windows 10, ...
Read more >
Question: How to upload a file using HTTP POST Form-Data?
I am looking to upload multipart for data, including a file, with an HTTP post. When implementing your example I do receive errors...
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