1
Following I am making the following mistake when calling a POST method
405 (Method Not Allowed)
follows the method I’m trying to call
@RequestMapping(value = "/upload", method = { RequestMethod.POST })
public @ResponseBody Object upload(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
System.out.println("upload() called");
if (file.isEmpty()) {
request.setAttribute("message", "Please select a file to upload");
return "uploadStatus";
}
try {
// for Fine Uploader delete functionality
String qquuid = request.getParameter("qquuid");
System.out.println("qquuid=" + qquuid);
if (qquuid != null) {
request.getSession().setAttribute(qquuid, file.getOriginalFilename());
}
// for Fine Uploader delete functionality ends
byte[] bytes = file.getBytes();
Path path = Paths.get(UPLOADED_FOLDER + file.getOriginalFilename());
Files.write(path, bytes);
request.setAttribute("message", "You have successfully uploaded '" + file.getOriginalFilename() + "'");
} catch (IOException e) {
e.printStackTrace();
}
return getSuccessMessage().toString();
}
and the code I’m using to call the method in jsp
$(function() {
$("#uploader").plupload({
// General settings
runtimes : 'html5,flash,silverlight,html4',
url : "sic/ito/upload",
// Maximum file size
max_file_size : '2mb',
chunk_size: '1mb',
// Resize images on clientside if we can
resize : {
width : 200,
height : 200,
quality : 90,
crop: true // crop to exact dimensions
},
// Specify what files to browse for
filters : [
{title : "Image files", extensions : "jpg,gif,png,docx,doc,xls,xlsx,pptx,ppt,pdf"},
{title : "Zip files", extensions : "zip,avi,rar"}
],
// Rename files by clicking on their titles
rename: true,
// Sort files
sortable: true,
// Enable ability to drag'n'drop files onto the widget (currently only HTML5 supports that)
dragdrop: true,
// Views to activate
views: {
list: true,
thumbs: true, // Show thumbs
active: 'thumbs'
},
// Flash settings
flash_swf_url : '/resources/plupload-2.3.1/js/Moxie.swf',
// Silverlight settings
silverlight_xap_url : '/resources/plupload-2.3.1/js/Moxie.xap'
});
});