1

I tried to upload image files to the serve with the help of connect-multiparty

router.post('/image', multipartMiddleware , function(req, res) {
  console.log(req.body, req.file);
});

<form method="post" action="/products/image">
    <input type="file" name="file">
    <input type="submit" value="Upload">
</form>

But the result of the above console is { file: '156.jpg' } undefined, i.e. I can get the file name, but why the file object is not coming?

nbro
  • 13,796
  • 25
  • 99
  • 185
Nichole A. Miler
  • 1,041
  • 2
  • 10
  • 20

1 Answers1

1

The file content is located in req.files not req.file in your code.

And the file path and file name can also be found

    var tmppath = req.files.file.path;
    var tmpname = req.files.file.name;

Here is one link, which I used to upload file with Node.js.

zangw
  • 37,361
  • 17
  • 142
  • 172
  • I didn't use native file upload so my object is different, I figured that out anyway. I'm using base64 so the approach is abit different, take a look http://stackoverflow.com/questions/34700883/base64-image-corrupted-uploading-to-s3 – Nichole A. Miler Jan 10 '16 at 01:06