SpringMVC+Postman进行文件上传测试

                              SpringMVC+Postman进行文件上传测试

 

一、软件下载

1、 https://www.getpostman.com/apps

2、若无法下载,可直接私信提供谢谢。

二、SpringMVC 后台上传部分代码

1、上传部分代码

/**
* description: 文件上传 upload
* @param uploadFile 文件上传对象
* @param path 文件存储路径
* @return String
* @version v1.0
* @author w
* @date 2018年10月17日 下午5:19:47
*/
@RequestMapping(value={"/upload"},method=RequestMethod.POST)
@ResponseBody
public String upload(MultipartFile uploadFile,String path){

    String originalFilename = uploadFile.getOriginalFilename();
    System.out.println(" originalFilename --->"+originalFilename);
    if(StringUtils.isBlank(path)){
        path="C:/";
    }
    File file=new File(path,DateUtils.getTimestamp()+originalFilename);
    try {
        uploadFile.transferTo(file);
        return "true";
    } catch (IllegalStateException | IOException e) {
        e.printStackTrace();
    }
        return "false";
}

2、补充:SpringMVC文件上传配置: https://blog.csdn.net/HaHa_Sir/article/details/79161225

三、postman 操作

1、请求调整为post, url 设置为: http://192.168.1.5:999/downloads/upload

2、form-data 参数设置:uploadFile(type=file) , path 。

3、选择上传文件,执行上传操作

四、测试

1、执行 Send 操作后,上传成功,返回 true 。

2、成功上传到F盘

参考资料: postman接口测试和压力测试

猜你喜欢

转载自blog.csdn.net/HaHa_Sir/article/details/83114474