美文网首页
00001.上传文件并使用soapui进行测试

00001.上传文件并使用soapui进行测试

作者: 笑着字太黑 | 来源:发表于2022-07-14 16:04 被阅读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')中的设定值保持一致)
    

    相关文章

      网友评论

          本文标题:00001.上传文件并使用soapui进行测试

          本文链接:https://www.haomeiwen.com/subject/igisbrtx.html