Skip to content

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

@jacargentina

Description

@jacargentina

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfeat:fetchIssues related to @remix-run/web-fetchfeat:forms

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions