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
  • 15,395
  • 32
  • 113
  • 196
Nichole A. Miler
  • 1,281
  • 2
  • 11
  • 21

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
  • 43,869
  • 19
  • 177
  • 214
  • 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