swagger2如何测试单个文件或者多文件上传(springboot)

单个文件

@ApiOperation(value = "上传视频接口",notes = "上传视频接口")
@ApiImplicitParams({
        @ApiImplicitParam(name = "uId",value = "上传用户ID,",paramType = "query",required = true,dataType = "int")
})
@PostMapping(value = "/video/uplode", headers = "content-type=multipart/form-data")
public ResponseJsonCode uplode(HttpServletRequest request,@RequestParam(value = "uId", required = true) String uId, @RequestParam(value = "file", required = true) MultipartFile file) {
    Map<String,Object> dataMap = new HashMap<String,Object>();
    String path="";
    log.info("file:"+file.length+"; uId:"+uId+"; path:"+path);
    List<Map<String,Object>> list =  IOUtil.appMvcUpload(path, file, request,dataMap);
    return null==list.get(0).get("error")?ResponseJsonCode.successRequestJsonCode(list):ResponseJsonCode.errorRequestJsonCode(list);
}

在这里插入图片描述
多文件(用postman测试)

@ApiOperation(value = "文件上传",notes = "文件上传")
@ApiImplicitParams({
        @ApiImplicitParam(name = "files",value = "多个文件,",paramType = "formData",allowMultiple=true,required = true,dataType = "file"),
        @ApiImplicitParam(name = "uId",value = "上传用户ID,",paramType = "query",required = true,dataType = "int")
})
@PostMapping(value = "/uplode", headers = "content-type=multipart/form-data")
public ResponseJsonCode uplode(HttpServletRequest request,@RequestParam(value = "uId", required = true) String uId, @RequestParam(value = "files", required = true) MultipartFile[] files) {
    Map<String,Object> dataMap = new HashMap<String,Object>();
    String path="";
    log.info("files:"+files.length+";uId:"+uId+":   path:"+path);
 
    List<Map<String,Object>> list =  IOUtil.appMvcUpload(path, files, request,dataMap);
    return null==list.get(0).get("error")?ResponseJsonCode.successRequestJsonCode(list):ResponseJsonCode.errorRequestJsonCode(list);
}

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

参考链接:https://blog.csdn.net/persistencegoing/article/details/87892640

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值