Search code examples
node.jsangularexpressmean-stackmulter

Unable to get req.file.path


I am getting req.file getting response as below

{ fieldname: 'product_image',
  originalname: '71ELL0gnILL._UL1500_.jpg',
  encoding: '7bit',
  mimetype: 'image/jpeg',
  buffer: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff db 00 43 00 05 03 04 04 04 03 05 04 04 04 05 05 05 06 07 0c 08 07 07 07 07 0f 0b 0b 09 ... >,
  size: 206437 }

but req.file.path I am getting undefined

This is form MEAN stack, I am uploading the file from client(Angular) and sending it to the NODE but it's not working.

Any one please help me in this.


Solution

  • In its default configuration multer will keep the whole file in memory and therefore the path property doesn't exist, since a file path only ever makes sense for files that have been stored on a file system.

    In order to have multer store uploaded files to disk, you have to pass an upload destination like so

    var upload = multer({ dest: 'uploads/' })
    

    or pass a customized DiskStorage as explained here.