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

  All rights reserved.No part of this article may be reproduced or distributed by any means,or stored in a database or retrieval system,without the prior written permission of persistenceGoing author


https://blog.csdn.net/persistencegoing/article/details/84376427

单个文件

@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 dataMap = new HashMap();
    String path="";
    log.info("file:"+file.length+"; uId:"+uId+"; path:"+path);
    List> list =  IOUtil.appMvcUpload(path, file, request,dataMap);
    return null==list.get(0).get("error")?ResponseJsonCode.successRequestJsonCode(list):ResponseJsonCode.errorRequestJsonCode(list);
}

swagger2如何测试单个文件或者多文件上传(springboot)_第1张图片

至于多文件的我想swagger应该不支持吧,反正我是没研究出来。。

 

多文件(用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 dataMap = new HashMap();
    String path="";
    log.info("files:"+files.length+";uId:"+uId+":   path:"+path);

    List> list =  IOUtil.appMvcUpload(path, files, request,dataMap);
    return null==list.get(0).get("error")?ResponseJsonCode.successRequestJsonCode(list):ResponseJsonCode.errorRequestJsonCode(list);
}

 

swagger2如何测试单个文件或者多文件上传(springboot)_第2张图片

如果postman测试文件上传,后台接受文件为null,则是你postman这边设置有问题

一是看请求方式

二是headers里面是空

swagger2如何测试单个文件或者多文件上传(springboot)_第3张图片

三是接受key是否正确

swagger2如何测试单个文件或者多文件上传(springboot)_第4张图片

四是文件类型是file

swagger2如何测试单个文件或者多文件上传(springboot)_第5张图片

五如果都正确,但是依旧接受是空

则把file类型变text,再重新选择file,重新选择文件上传,这大概是postman的bug吧,我刚刚遇到了,而且我uId是,2      接受了的时候莫名多了一个逗号,再这个一顿瞎几把操作之后就正常了

 

 

如果有帮助到你的话,请记得关注一波

博主强烈推荐:https://blog.csdn.net/persistencegoing/article/details/84376427

希望大家关注我一波,防止以后迷路,有需要的可以加群讨论互相学习java ,学习路线探讨,经验分享与java求职  

群号:721 515 304

你可能感兴趣的:(springboot)