MulterError:意外字段,reactjs,vuejs,nodejs

时间:2018-10-31 14:45:25

标签: node.js reactjs vue.js vuejs2 multer

route.js

menu[userInput]

imageUpload.js或imageUpload.vue或imageUpload.vue.jsx

var menu = [
  "0 = Calzone",
  "1 = Ost & Skinke",
  "2 = Margarita",
  "3 = BBQ Grill"
];

var userPostnummer = prompt("skriv inn postnummer")

if (userPostnummer >= 1000 && userPostnummer <= 1999) {
  alert("gratulerer du får et gratis pizza")
  var userInput = prompt("hvilket meny ønsker du å bestille?" + menu); 
  // Alert is now on its own row.
  // userInput is also replaced with menu[userInput]
  if (userInput < menu.length)
    alert("pizza " + menu[userInput] + " er på vei til postnummer " + userPostnummer)

} else {
  alert("beklager, du er ikke i området hvor vi tilbyr gratis pizza")
};

每当我尝试将图像上传到cloudinary云存储时都会出错。

2 个答案:

答案 0 :(得分:0)

更改route.js

 const multerName = 'MyImage'
 app.post('/api/images', parser.single(multerName), function(req, res){

mageUpload.js或imageUpload.vue或imageUpload.vue.jsx

const multerName = 'MyImage'
data.append("name", "orderImage");

这里的multerName也与route.js相同

data.append("multerName", event.target.files[0]);

答案 1 :(得分:0)

更改route.js

 const multerName = 'MyImage'

 app.post('/api/images', 
    parser.single('anotherFile'), //here exact change
       function(req, res){

更改后

app.post('/api/images', parser.single('anotherFile'), function(req, res){

mageUpload.js或imageUpload.vue或imageUpload.vue.jsx

const multerName = 'MyImage'
data.append("name", "orderImage");

这里的multerName也与route.js相同

data.append("file",  //here exact change
   event.target.files[0]);

更改后

 data.append("multerName", event.target.files[0]);

需要在前端和后端formData()中保持相同的名称