栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

postman文件上传springboot的过程

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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;


@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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/685554.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号