Because the image is uploaded using binary mode, the method of using hidden fields is invalid, and the method of conversion is as follows:
Https://www.cnblogs.com/morethink/p/6378015.html
But then I had another requirement. That is, when the changes need to transfer files to the Put method, so this method is not OK, but I see in the HiddenHttpMethodFilter
source code this sentence
1 Case of a multipart 2 for checking a POST body parameter.</b>3 * so typically, put a Spring {@link Org.springfra Mework.web.multipart.support.MultipartFilter}4This hiddenhttpmethodfilter in Your {@code web. xml} filter chain.
and multipartfilter the source code in such comments
1 /** 2 * Set The bean name of the multipartresolver to fetch from Spring ' s3 * Root application con Text. Default is "Filtermultipartresolver". 4 */
- That means we can register a multipartfilter in Web. XML,be sure to Hiddenhttpmethodfilter before the。
1<filter>2<filter-name>MultipartFilter</filter-name>3<filter-class>org.springframework.web.multipart.support.multipartfilter</filter-class>4</filter>5<filter-mapping>6<filter-name>MultipartFilter</filter-name>7<servlet-name>dispatcher</servlet-name>8</filter-mapping>9 Ten<filter> One<filter-name>HiddenHttpMethodFilter</filter-name> A<filter-class>org.springframework.web.filter.hiddenhttpmethodfilter</filter-class> -</filter>
- Then add the following code in the Spring root application context
<bean id= "Filtermultipartresolver" class= " Org.springframework.web.multipart.commons.CommonsMultipartResolver "> <property name=" Maxuploadsize " Value= "209715200"/> <property name= "defaultencoding" value= "UTF-8"/> <property name= " Resolvelazily "value=" true "/></bean>
- The Formdata object is an object of HTML5, and some of the mainstream browsers are now compatible. The Formdata object is an object of HTML5, and some of the mainstream browsers are now compatible.
function Test () {var form=NewFormData (document.getElementById ("TF")); Form.append ("_method", ' Put '); $.ajax ({url:url, type:' Post ', Data:form, ProcessData:false, ContentType:false, Success:function (data) {Window.clearinterval (timer); Console.log ("Over.."); }, Error:function (e) {alert ("Error!! "); Window.clearinterval (timer); } }); Get ();//here is the progress bar for uploading files }<form id= "TF" method= "POST" name= "Formdada" enctype= "Multipart/form-data" > <input type= "file" name= "file"/& Gt <input type= "text" name= "id"/> <input type= "text" name= "name"/> <input type= "button" value= "Lift" onclic k= "Test ()"/></form>
Finally, it is possible to submit a file upload to the Put method.
springmvc-implement put request upload file (go)