Multer is Express middleware that provides everything that we need to parse a multipart/form-data upload by its field name. By default, it writes the file to our operating system's disk, which we can configure by providing a destination file path during initialization.
The req.file object is a reference object that Multer leaves on the Express request option, with which we can interrogate the file that was uploaded. There are many different properties in this object, each containing different information we might want to know about the file:
Property | Description |
fieldname |
The multipart/form-data field that contains the uploaded image |
originalname |
The uploaded image's original filename |
encoding |
The encoding type of the uploaded file |
mimetype |
The mime type of the uploaded image |
size |
The file size of the uploaded image in bytes |
destination |
The name of the directory where the uploaded image is saved |
filename |
The renamed filename of the uploaded image in your upload directory |
path |
The relative file path where the uploaded image is saved |
buffer |
The raw file buffer for the uploaded image |
We will also be doing a bit more advanced configuration with Multer in the next recipe - Uploading images to Cloudinary from Express.