In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
In this issue, Xiaobian will bring you about how to analyze springboot multi-file upload examples and how to write code. The article is rich in content and analyzed and described from a professional perspective. After reading this article, I hope you can gain something.
an illustration
spingMVC supports file upload. We implement spingMVC MultipartResolver through CommonsMultipartResolver of Apach commons-fileupload package.
The example in this article is a simple multi-file upload, modified for different businesses.
2 pom.xlm
commons-fileupload commons-fileupload 1.3.3 org.springframework.boot spring-boot-starter-web
3 application.yml
spring: servlet: multipart: max-file-size: 200MB #Single file upload size max-request-size: 600MB #Continuous upload file size youku1327: file: root: path: "C:\\mydata\\generator\\version06\\" #Storage path
Four controllers
/** * @Author lsc * @Description
* @Date 2019/10/2 20:58 * @Version 1.0 */@RestControllerpublic class FileUploadController { @Value ("${youku1327.file.root.path}") private String fileRootPath; @PostMapping ("/file/upload") public String fileUpload (@RequestParam("files")MultipartFile[] files){ String filePath = ""; //multifile upload for (MultipartFile: files){ //Upload simple filename String originalFilename = file.getOriginalFilename(); //Storage path filePath = new StringBuilder (fileRootPath) .append(System.currentTimeMillis()) .append(originalFilename) .toString(); try { //save file.transferTo(new File(filePath)); } catch (IOException e) { e.printStackTrace(); } } return filePath; }}
Five start classes
/** * @Author lsc * @Description
* @Date 2019/10/2 20:54 * @Version 1.0 */@SpringBootApplicationpublic class FileUploadApplication { public static void main(String[] args) { SpringApplication.run(FileUploadApplication.class,args); }}
sixth test
Send http post request, using form, key files need to be consistent with the parameter name of MultipartFile[], select two files, after sending successfully, you will see the final file path returned;
Open the saved file path to find that the file has been uploaded.
The above is how to analyze the springboot multi-file upload example and how to write the code shared by Xiaobian. If there is a similar doubt, please refer to the above analysis for understanding. If you want to know more about it, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.