These two days the boss suddenly to a task, that is, when the user concerned about our number, we should download its avatar, and then uploaded to the company's internal server. If you save the link to the avatar directly, when the user changes the avatar, it is likely that our product will have a 404 exception in obtaining the user's avatar.Due to the technology stack used by the company for Spring Cloud (some eureka, feign) for service registration and remote invocation.The point is that ....
One, the configuration file:Springmvc used the Multipartfile to upload the file, so we'll first configure the Multipartresolver: To process the form fileConfigure Multipartresolver for file uploads using spring's commosmultipartresolver - Beans:beanID= "Multipartresolver"class= "Org.springframework.web.multipart.commons.CommonsMultipartResolver"p:defaultencoding= "UTF-8"p:maxuploadsize= "5400000"P:uploadtempdir= "Fileupload/temp" > Bea
One, the configuration file:Springmvc used the Multipartfile to upload the file, so we'll first configure the Multipartresolver: To process the form fileThe attributes are detailed in the following:Defaultencoding= "UTF-8" is the requested encoding format, the default is Iso-8859-1Maxuploadsize= "5400000" is the size of the uploaded file, in bytesUploadtempdir= "Fileupload/temp" is the temporary path for uploading filesSecond, create a simple upload f
The basic SPRINGMVC has been written in my last article, which explains how to use Springmvc to upload files on a form and upload multiple files at the same time.
File Upload Project source code download address: Demo
First, the configuration file:
Springmvc used Multipartfile to upload files, so we're going to first configure the Multipartresolver: To work with the file in the form
Where the attributes are detailed:
Defaultenc
The company's projects in many places to use the file upload, the previous upload is mainly using Apache FileUpload, the use of the feeling is not very good. Try spring Multipartfile today, feel good, the package is relatively concise.Of course, the middle also ruled out a lot of pits.1. Configure Commonsmultipartresolver1 Configure Multipartresolver for file uploads using spring's commosmultipartresolver -2 BeanID= "Multipartresolver"class= "
Springmvc file upload, first two basis, 1. Form form Properties plus enctype= "Multipart/form-data"
Emphasis: Form form's
2. Configure Multipartresolver in configuration file
A file exceeding the limit throws an exception before entering the controller, which does not affect the configuration within the allowable range
3. A simple way of receiving, thinking: Multipartfile accept the file and through the IO binary stream (Multipartfile.getinputstr
individual file Upload development steps:
1. Add Apache file upload jar package
First you need to download the jar package for two Apache upload filesCommons-fileupload-1.3.1.jarCommons-io-2.4.jarDepending on the project, select the version you are using.2. Configuring Multipartresolver Processing Files
Springmvc used the Multipartfile to upload the file, so we'll first configure the Multipartresolver: To work with file in the form.
Property D
Using spring's multipartfile to implement file uploads is primarily dependent on the jar packageSpring-web-3.0.6.release.jar (Org.springframework.web.multipart.MultipartFile)Commons-fileupload-1.3.1.jarCommons-logging-1.0.4.jarFront deskDOCTYPE HTML>HTMLLang= "en">Head>MetaCharSet= "Utf-8">title>Uploadtitle>styletype= "Text/css">style>Head>Body> formenctype= "Multipart/form-data"Action= "/kingtool/file/upload.do"Method= "POST">File:inputtype= "File
Reprinted from: http://blog.csdn.net/u013771277/article/details/47384817
Springmvc file Upload, first two base, 1. Add Enctype= "Multipart/form-data" to form form properties
Emphasis: Form form
2. Configuration file in configuration Multipartresolver
File out-of-bounds will throw an exception before entering the controller, without affecting the configuration within the allowed range
3. Simple Receive method, idea: Multipartfile accept the file
Basic SPRINGMVC in my previous article has been written, this article mainly explains how to use Springmvc to upload files on the form and multiple files simultaneously upload the stepsSPRINGMVC Basic Tutorial Framework Analysis: http://blog.csdn.net/swingpyzf/article/details/8885459
SPRINGMVC Basic Tutorial Simple Getting Started example: http://blog.csdn.net/swingpyzf/article/details/8904205
File Upload Project source code download address: http://download.csdn.net/detail/swingpyzf/6979915
For a form with a file upload, the background uses the SPRINGMVC encapsulated Multipartfile file to receive files, and you need to use asynchronous commit, and return the appropriate prompt informationUse jquery's form plug-in, which is jquery.form.js the plugin, and then use the plugin's Ajaxsubmit method;1$ ("#pageForm"). Ajaxsubmit ({2Type: "POST",3URL: "Your action.html",4DataType: "JSON",5Successfunction(data) {6 if(data.msg== ' SUCCESS '
Method in Controller Public String excelinsertteachers (multipartfile file,httpservletrequest request, HttpSession session, HttpServletResponse response) throws illegalstateexception, IOException {}This method may go many times, but there is no upload file operation, then this method will have an exception, how to solve it? PublicString excelinsertteachers (httpservletrequest request, HttpSession session, HttpServletResponse Response) thro
Error background: Since the file is stored on a third-party server, all need to be told to convert the received Multipartfile file to files and then transfer. (Spring MVC)The following two methods have been found through search engines.are declared in the preceding spring XML. As follows:id= "Multipartresolver" class= " Org.springframework.web.multipart.commons.CommonsMultipartResolver "/> If you want to add the largest, minimum range control, pleas
One, the configuration file:Springmvc used the Multipartfile to upload the file, so we'll first configure the Multipartresolver: To process the form file[HTML] view Plain copy The attributes are detailed in the following:Defaultencoding= "UTF-8" is the requested encoding format, the default is Iso-8859-1Maxuploadsize= "5400000" is the size of the uploaded file, in bytesUploadtempdir= "Fileupload/temp" is the temporary path for uploading files
Second,
file uploads using spring's commosmultipartresolver - Beans:beanID= "Multipartresolver"class= "Org.springframework.web.multipart.commons.CommonsMultipartResolver"p:defaultencoding= "UTF-8"p:maxuploadsize= "5400000"P:uploadtempdir= "Fileupload/temp" > Beans:bean> The attributes are detailed in the following:Defaultencoding= "UTF-8" is the requested encoding format, the default is Iso-8859-1Maxuploadsize= "5400000" is the size of the uploaded file, in bytesUploadtempdir= "Fileuplo
removed and the problem is resolved.3. Single file only need a variable that is, multi-file upload the words will be multipartfile to the array, and then upload and save separately.[Java]View PlainCopy
@RequestMapping (value="/multiplesave", Method=requestmethod.post)
public @ResponseBody String multiplesave (@RequestParam ("file") multipartfile[] files) {
String fileName = null;
String msg =
Error background: Because the file is stored on a third party server, all need to speak will receive the Multipartfile file to convert to file and then transfer. (Spring MVC)
The following two methods were found through the search engine.
are declared in the spring XML. As follows:
If you need to add the largest, minimum and other scope control, please own Baidu reference.
Method One: Strong turn
Method Two:
1 2 3
Commonsmultipartfil
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.