Nextjs sends file with undefined name
Unanswered
Chinese softshell turtle posted this in #help-forum
Chinese softshell turtleOP
I have a form with plain
And form handler being a server action:
Which is strange, because I expected it to be null. I know I can just check for size === 0, but I'm curious if it is some documented behaviour or even if Nextjs is responsible for this (maybe it's a browser thing).
<input type="file"/>, with a handler onChange={(e) => {
const file = e.target.files?.item(0) ?? null;
setFileSelected(file);
}}And form handler being a server action:
action={action}. However, when file is not selected (it is reflected by file state being set to null), in my Server action, after getting this file from FormData, I get this placeholder, instead of null:File {
size: 0,
type: 'application/octet-stream',
name: 'undefined',
lastModified: 1692780165744
}Which is strange, because I expected it to be null. I know I can just check for size === 0, but I'm curious if it is some documented behaviour or even if Nextjs is responsible for this (maybe it's a browser thing).