-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix file exists but file name does not exist #1216
base: master
Are you sure you want to change the base?
Conversation
if (!filename) { | ||
// @link https://github.com/mscdex/busboy/blob/master/lib/types/multipart.js | ||
// If the type is 'application/octet-stream', it is also identified as a file | ||
if(mimetype==='application/octet-stream'){ | ||
filename = 'unknownFile' | ||
}else{ | ||
return fileStream.resume() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey team!
I've been thinking about the current implementation of this if
statement. It might be beneficial for us to consider allowing undefined
filenames. This change would give developers more flexibility in handling cases where a client does or does not provide a filename
field. This can be pretty important for certain applications.
I wanted to share an interesting point that @Relsoul brought up regarding RFC 7578. The RFC mentions that the filename
in the content disposition is recommended but not mandatory. It states:
For form data that represents the content of a file, a name for the file SHOULD be supplied as well, by using a 'filename' parameter of the Content-Disposition header field.
...
The file name isn't mandatory for cases where the file name isn't available or is meaningless or private
With this in mind, it seems quite likely that developers using Multer would appreciate the ability to handle RFC-compliant uploads in a way that best suits their needs, especially when a filename isn't provided. For example, in our system, we prefer storing NULL
in the database for the "original file name" if the uploader doesn't provide it, instead of assigning a default value.
Interestingly, busboy
allows for undefined filenames, which is a great feature for flexibility. I think it might be a good idea for multer to adopt a similar approach. What do you all think?
To gain parity with busboy, it would simply be a case of removing this entire if
statement, and acknowledging that the originalname
field may be undefined
to reflect RFC 7578:
if (!filename) { | |
// @link https://github.com/mscdex/busboy/blob/master/lib/types/multipart.js | |
// If the type is 'application/octet-stream', it is also identified as a file | |
if(mimetype==='application/octet-stream'){ | |
filename = 'unknownFile' | |
}else{ | |
return fileStream.resume() | |
} | |
} |
yep, In the browser environment, formData.append(name, value, filename); The filename is optional, but the browser will automatically add a filename for Blob/File type objects. However, in other environments, the filename may not be automatically added. When I use a buffer for direct upload, I might ignore the filename. In Node Express, this is reflected in that if the filename does not exist, it skips the destination function and filename function. |
https://www.rfc-editor.org/rfc/rfc1867
file name is an optional field.
eg.