In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "SpringBoot+BootStrap multi-file upload method to the local", the editor shows you the operation process through the actual case, the operation method is simple and fast, practical, I hope that this "SpringBoot+BootStrap multi-file upload method to the local" article can help you solve the problem.
1. Application.yml file configuration # File size MB must be uppercase # maxFileSize is a single file size # maxRequestSize is to set the total uploaded data size spring: servlet: multipart: enabled: true max-file-size: 20MB max-request-size, application-resources.yml configuration (custom attributes) # File upload path file: filepath: O:/QMDownload/Hotfix2/3, backend code (1) FileService.javapackage com.sun123.springboot.service Import org.springframework.web.multipart.MultipartFile;import java.util.Map;public interface FileService {Map fileUpload (MultipartFile [] file);} (2) FileServiceImpl.javapackage com.sun123.springboot.service.impl;import com.sun123.springboot.FileUtil;import com.sun123.springboot.service.FileService;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Value;import org.springframework.stereotype.Service;import org.springframework.web.multipart.MultipartFile Import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.File;import java.io.FileInputStream;import java.io.PrintWriter;import java.util.*;/** * @ ClassName FileServiceImpl * @ Description TODO * @ Date 22:19 on 2019-3-22 * @ Version 1.0 * / @ Servicepublic class FileServiceImpl implements FileService {private static Logger log= LoggerFactory.getLogger (FileServiceImpl.class) / / the file upload path @ Service contains @ Component @ Value ("${file.filepath}") private String filepath; Map resultMap = new LinkedHashMap (); / / the upload information will be stored here, and List fileName = new ArrayList () will be adjusted according to the requirements; / / must be injected, objects cannot be created, otherwise the path attribute referenced by the configuration file will be null @ Autowired FileUtil fileUtil @ Override public Map fileUpload (MultipartFile [] file) {HttpServletRequest request = null; HttpServletResponse response; resultMap.put ("status", 400); if (fileholders containing nulllength length > 0) {/ / combined image name, "; separated" / / List fileName = new ArrayList (); PrintWriter out = null / / upload try {for (int I = 0; I)
< file.length; i++) { if (!file[i].isEmpty()) { //上传文件,随机名称,","分号隔开 fileName.add(fileUtil.uploadImage(request, filepath+"upload/"+ fileUtil.formateString(new Date())+"/", file[i], true)+fileUtil.getOrigName()); } } //上传成功 if(fileName!=null&&fileName.size()>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.