Problem uploading a file with ajax in appengine
I need to send the content of a file to a Spring webService with Ajax in a Google AppEngine Application. So I've used jquery ajaxFileUpload plugin.
<form id="load_form" action="" enctype="multipart/form-data">
<input name="file" type="file" id="upload_files" value="Browse"/>
<input type="button"" id="upload_file" value="Load file"/>
</form>
The javascript looks like this:
$("#upload_file").click(function(){
$.ajaxFileUpload
(
{
url: '/myproject/uploadFile.json',
secureuri: false,
fileElementId: 'upload_files',
dataType: 'json',
success: function (data, status) {
alert("OK");
},
error: function (data, status, e) {
alert("Error");
}
}
);
return false;
});
and in the controller:
@RequestMapping(value="/uploadFile.json", method=RequestMethod.POST)
public Map<String, Object> readFile(开发者_如何学Go
@RequestParam(value = "file", required=false) MultipartFile file,
Model model) throws Exception{
...
}
The problem I'm having is that I'm not receiving in the file parameter the file content (it's always null) and with firebug I can see that I'm sending the content of the file in a parameter called "file". But I'm not receiving them though this method is invoked (I have a breakpoint in it and it stops in it). If I remove required=false from file param a 400 error is given, so it looks as it cannot find the file param.
I'm using Spring 3.0.4.
Any idea of what may be happening?
Thanks.
If you are result oriented in this case, you can use custom servlet.
精彩评论