00001.上传文件并使用soapui进行测试
2022-07-14 本文已影响0人
笑着字太黑
route.js(注意uploads.single('file')中的file,稍后要与soapui中的ContentID保持一致)
var multer = require('multer'); //解析Post文件
var uploads = multer({
dest: '../uploads/'
});
var uploadController= require("../controller/UploadController.js");
app.post('/api/v1/uploadImg', uploads.single('file'), uploadController.uploadImg);
UploadController.js
const fs = require('fs');
class UploadController {
async uploadImg(req, res) {
let oldName = req.file.path;
let newName = 'upload/'+req.file.originalname
fs.renameSync(oldName, newName);
res.send({
err: null,
url: "http://localhost:3000/" +newName
});
}
}
module.exports = new UploadController();
sopaui
1.method选择post
2.media type选择multipart/form-data
3.Attachment中选择+,添加附件
4.修改Attachment的ContentID为file(与uploads.single('file')中的设定值保持一致)