postman文件上传springboot的过程

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
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值