前言
使用postman模仿前端上传文件
1、修改工作区
进入设置 file -> settings,上传的文件必须在设置的工作区中,不然会报错:
This file isn't in your working directory. Teammates you share this request with won't be able to use this file. To make collaboration easier you can setup your working directory in Settings.
2、设置请求头
3、设置请求体
MultipartFile file,上图
请求体 form-data 的 KEY 值和此处的 file 名保持一致,否则后端接收不到文件,报空指针异常 NullPointerException
@PostMapping(path = "/upload")
public void uploadHeader(MultipartFile file){
...
}