How can I get file size inside fileFilter function?
See original GitHub issueAm I have any way to get file size inside fileFilter function?
var fileFilter = function (req, file, cb) {
console.log(file.size); // undefined
}
I have only four first keys in file
variable
Key | Description | Note |
---|---|---|
fieldname |
Field name specified in the form | |
originalname |
Name of the file on the user’s computer | |
encoding |
Encoding type of the file | |
mimetype |
Mime type of the file | |
size |
Size of the file in bytes | |
destination |
The folder to which the file has been saved | DiskStorage |
filename |
The name of the file within the destination |
DiskStorage |
path |
The full path to the uploaded file | DiskStorage |
buffer |
A Buffer of the entire file |
MemoryStorage |
Issue Analytics
- State:
- Created 8 years ago
- Reactions:8
- Comments:20 (6 by maintainers)
Top Results From Across the Web
How to limit the file size when uploading with multer?
var maxSize = 1 * 1000 * 1000; var storage = multer. diskStorage({ destination: function (req, file, callback) { callback(null, 'public/upload' ...
Read more >Node.js Multer File Upload Type Validation Filters and Limit ...
Node.js Multer File Upload Type Validation Filters and Limit File Size and Error Handling in ExpressDownload the full source code of ...
Read more >Express multer middleware
File information ; mimetype, Mime type of the file ; size, Size of the file in bytes ; destination, The folder to which...
Read more ><input type="file"> - HTML: HyperText Markup Language | MDN
The returnFileSize() function takes a number (of bytes, taken from the current file's size property), and turns it into a nicely formatted size ......
Read more >Configuring Express Multer Middleware and Checking File ...
Defaults to Infinity; fileSize — maximum file size in bytes. ... The fileFilter field is a function that lets us control which files...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop 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
Top GitHub Comments
Oh, actually that is very easily solvable in a clean way for you!
The
fileSize
limit will automatically remove the file if it received a too large file, read more in the readme 😃I’m sorry to say that
file.size
is only available after the file has been received.This could possibly be fixed by looking at the
Content-Length
header of that part, but I do not yet know if browsers send those.