IE8 file upload problem with jquery form + Spring MVC controller returning XML -


i developing component uploading images based on jquery form , spring mvc controller produces xml object containing url of new image on server. jquery code on client side is:

$('#uploadform').ajaxform({ beforesubmit : function(a, f, o) {     $('#uploadoutput').html('uploading...'); }, success : function(response) {     var $out = $('#uploadoutput');     var url = $(response, 'url').text();     $out.html('<img src="'+url+'4" alt="'+url+'"/>'); }, datatype : "xml"}); 

my form is:

<form id="uploadform" action="http://localhost:8080/gossipdressrest/rest/imageupload/1" method="post" enctype="multipart/form-data"> <input type="hidden" name="max_file_size" value="100000" />  <input type="file" name="file" /> <input type="submit" value="submit" /> 

and spring mvc controller is:

@requestmapping(value = "/rest/imageupload/{personid}", method = requestmethod.post) public @responsebody imageurl save(@pathvariable("personid") long personid,         @requestparam("file") multipartfile file) {     try {         imagepk pk = imagemanager.storetmpimage(personid, file.getbytes());         imageurl imageurl = new imageurl();         imageurl.seturl(imageurlresolver.geturl(pk));         return imageurl;     } catch (exception e) {         logger.error(e.getmessage(), e);         throw new runtimeexception(e);     } } 

imageurl pojo single attribute 'url' of type string. containing url of uploaded image. above code works correctly in firefox , chrome, in ie8 causes make 2 requests server:

the first seems correct , identical generated firefox , chrome. generates request results in error 405.

request 1: post / http/1.1 gossipdressrest/rest/imageupload/1

http/1.1 200 ok server: apache-coyote/1.1 content-type: application / xaml + xml transfer-encoding: chunked date: thu, april 28, 2011 19:56:17 gmt  9e <? xml version = "1.0" encoding = "utf-8" standalone = "yes"?> <imageurl> <url> http://localhost:8080/gossipdressrest/image/1/tmp/-7884109442646822710/ </ url > </ imageurl> 0 

request 2: /gossipdressrest/rest/imageupload/1 http/1.1

http/1.1 405 m�todo no permitido  server: apache-coyote/1.1 allow: post content-type: text/html;charset=utf-8 content-length: 1097 date: thu, 28 apr 2011 19:56:17 gmt  <html><head><title>apache tomcat/6.0.29 - informe de error</title>... 

any idea ;-)

a bit late, perhaps response can serve other peoples.

this caused because mime type set application/x-ms-application or this.

you have set need application/json instance.

if you're using spring 3.1 or later, resquestmapping should this:

@requestmapping(value = "/rest/imageupload/{personid}", method = requestmethod.post, produces = mediatype.application_json_value) 

below spring 3.1, have "manually" set mime type in response.


Comments