How to send data along with file in http POST (angularjs + expressjs)?

后端 未结 3 1007
天命终不由人
天命终不由人 2021-01-14 02:41

Situation

I implemented file uploading. Front-end code is taken from popular tutorial. I send POST in service:

myApp.service(\'fileUpload\', [\'$http         


        
3条回答
  •  迷失自我
    2021-01-14 03:33

    You can get the file from req.files and save it with fs.writeFile.

    fs.readFile(req.files.formInput.path, function (err, data) {
      fs.writeFile(newPath, data, function (err) {
        if (err) {
        throw err;
        }
        console.log("File Uploaded");
      });
    });
    

提交回复
热议问题