如何测试Springboot文件上传功能

  介绍

这篇文章主要讲解了如何测试Springboot文件上传功能,内容清晰明了,对此有兴趣的小伙伴可以学习一下,相信大家阅读完之后会有帮助。

在静态文件夹中创html页面

内容为:

& lt; html>   & lt; head> & lt;/head>   & lt; body>   action=& lt;形式“/fileuploadContorller"方法=皃ost"enctype=岸嗖糠?form-data"比;   & lt;输入类型=癴ile"name=癴ile"/比;   & lt;输入类型=皊ubmit"值=https://www.yisu.com/zixun/碧峤?>   

创建控制器

包com.mc_74120.springbootfileupload.controller;
  
  进口org.springframework.web.bind.annotation.PostMapping;
  进口org.springframework.web.bind.annotation.RequestMapping;
  进口org.springframework.web.bind.annotation.RestController;
  进口org.springframework.web.multipart.MultipartFile;
  进口java.io.File;
  进口java.io.IOException;
  @RestController
  公开课FileUpLoadController {
  @PostMapping (“/fileuploadContorller")
  公共字符串fileUpLoadController (MultipartFile文件)抛出IOException {//MultipartFile对象的名称必须和html中的文件上传标签的名字相同
  System.out.println (file.getOriginalFilename ());
  文件。transferTo(新文件(“d:/? file.getOriginalFilename ()));
  返回“ok";
  }
  }

选择文件

如何测试Springboot文件上传功能

发送

找到该图片

如何测试Springboot文件上传功能

在应用配置文件中可以配置文件的大小和请求请求的大小

#配置单个文件的大小
spring.servlet.multipart.max-file-size=5 mb
#配置一次请求总容量大小
spring.servlet.multipart。max-request-size=10 mb

看完上述内容,是不是对如何测试Springboot文件上传功能有进一步的了解,如果还想学习更多内容,欢迎关注行业资讯频道。

如何测试Springboot文件上传功能