I am developing a component for uploading images based on a jquery form and spring mvc controller, which creates an xml object containing the URL of the new image on the server. My client side jquery code:
$('#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:
<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 my spring MVC controller:
@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 is a POJO with a single 'url' attribute of type String. Contains the URL of the uploaded image. The above code works correctly in firefox and chrome, but in IE8 it calls two requests to the server:
The first seems correct and identical to the one generated by firefox and chrome. But it generates another GET request, which results in a 405 error.
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: GET / 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; -)