文章目录
- Postman 调用文件上传接口
- Postman 简介
- Spring Boot 定义文件上传的接口
- Postman 调用文件上传接口
- 文件上传接口源码
- 参考文献
Postman 调用文件上传接口
Postman 简介
Postman 是一个用于构建和使用 API 的 API 平台。
Postman 简化了 API 生命周期的每一步,并优化了协作,因此您可以更快地创建更好的API。
简单点说:postman 发送请求给服务器,然后从服务器接受响应,最后在postman中展示出来。
Spring Boot 定义文件上传的接口
package com.joe.file.controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
/**
* @Author: 高建伟-joe
* @Date: 2022-12-05
* @Description: 文件上传 控制器
*/
@RequestMapping("/file")
@RestController
public class FileController {
@PostMapping("/upload")
public String upload(HttpServletRequest request){
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
MultipartFile file = multipartRequest.getFile("file");
String businessCode = request.getParameter("businessCode");
if (null == file){
return "获取文件失败";
}
if (!StringUtils.hasLength(businessCode)){
return "业务类型为空";
}
// todo 保存文件
// todo 保存文件上传记录
return "文件上传成功";
}
}
Postman 调用文件上传接口
请求参数
| 地址 | 请求方式 | Content-Type | 参数 |
|---|---|---|---|
| http://localhost:8080/file/upload | Post | multipart/form-data | { “file”: fileObject, “businessType”: “test” } |
Postman 调用截图
-
请求头设置 Content-Type

-
请求体设置

-
接口断点调试

-
响应

文件上传接口源码
点击下载
参考文献
Postman 官方文档
Postman 中文文档




![[附源码]Python计算机毕业设计SSM交通事故记录信息管理系统(程序+LW)](https://img-blog.csdnimg.cn/5ea282dbacd44ea886358f608263a82c.png)








![[附源码]Python计算机毕业设计Django数字乡村基础治理系统](https://img-blog.csdnimg.cn/7f73ea90c4ae4a5189ea857db15598d9.png)





