0

I try to do simple upload in node.js, So I upload a file via my browser, and my server should get this file.

I have the next methods:

app.post('/saveDocument', function  (req, res){
    var fileName = req.body.name;
    fs.readFile(req.file,  function (err, data) {
        fs.writeFile("./myStorage/" + fileName, data, function (err) {
        });
    })
    FileServer.prototype.returnRes(res, 200);
});

and my HTML is:

<html>
<head>
<title>Upload Example</title>
</head>
<body>

<form id="uploadForm"
      enctype="multipart/form-data"
      action="/saveDocument"
      method="post">
  <input type="file" id="userPhotoInput" name="displayImage" />
  <input type="submit" value="Submit">
</form>

<span id="status" />
<img id="uploadedImage" />


</body>
</html>

I get the next error: TypeError: path must be a string

What I do wrong?

david
  • 17,925
  • 4
  • 43
  • 57
Or Smith
  • 3,556
  • 13
  • 42
  • 69

1 Answers1

0

You are doing it wrong, you must manage the multi-part form. See this answer : File uploading with Express 4.0: req.files undefined

Community
  • 1
  • 1
Kevin Labécot
  • 2,005
  • 13
  • 25