postman文件上传springboot的过程
在springboot的controller中,有一个文件上传接口,使用postman调用。
请求是一个过程,在request携带着文件完整地到达服务器后,服务才算收到了这次请求,才会开始处理。
这中间取决于本地的上行速度和服务器的下行速度,会消耗掉一段时间。
上行:往网络发送数据;
下行:从网络接收数据。
文件越大,时间相应地也越长。
(我们从网上下载一个东西还需要时间呢)
如果请求设置有超时时间,时间又很短的话,可能出现以下情况:
1、在超时时间内,request还没有携带文件完整地抵达服务器,
这个时候取消了请求,服务没有接收到请求,服务不会进行处理。
2、request携带文件抵达服务器耗时较长,服务刚接收到请求,
这个时候取消了请求,不再接收服务器响应,但服务会继续处理。
本地模拟
package com.example.duohoob.controller;
import java.util.Date;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
/**
* @Title: FileController.java
* @Package com.example.duohoob.controller
*
* @author yangwei
* @date 2021年12月31日
*/
@RestController
@RequestMapping("/file")
public class FileController {
@RequestMapping("/upload")
public String upload(MultipartFile file) {
System.out.println("发起请求时间:" + new Date(System.currentTimeMillis()));
// 模拟request携带file到服务器所消耗时间
try {
Thread.sleep(3000); // 等待3秒
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(file.getOriginalFilename());
System.out.println("收到文件时间:" + new Date(System.currentTimeMillis()));
return "ok";
}
}
postman设置请求超时时间
单位毫秒
上传文件
发起请求时间:Fri Dec 31 15:01:42 CST 2021
test.txt
收到文件时间:Fri Dec 31 15:01:45 CST 2021