submit multipart/form-data with empty file input, got error on request.formData()
See original GitHub issueWhat 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:
- Created a year ago
- Comments:5 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
@mcansh seems to be working fine now 🎉