Well I'm having problems with this plugin I would like to know if someone has already messed with it and if it could help in the question
I'm having problems communicating with the controller I'm taking the following error 405 Method Not Allowed, but just at the time of use of this plugin the other functions of my system as registration query are ok
My controller that receives the request follows
@RequestMapping(value = "/carregarupload", 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 {
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();
}
private JSONObject getSuccessMessage() {
JSONObject jsonObject = null;
try {
jsonObject = new JSONObject("{\"success\":true}");
} catch (Exception e) {
e.printStackTrace();
}
return jsonObject;
}
and also follows the page requesting the post along with the plugin script
<div class="containerK">
<form enctype="multipart/form-data" method="${methodName}"
action="${action}">
<div class="form-group">
<input id="file-1" name="file" type="file" multiple class="file"
data-overwrite-initial="false" data-min-file-count="1">
</div>
</form>
</div>
<script>
$(document).ready(function() {
$("#file-1").fileinput({
uploadUrl : '/upload', // you must set a valid URL here else you will get an error
allowedFileExtensions : [ 'jpg', 'png', 'gif', 'war' ],
overwriteInitial : false,
maxFileSize : 10000,
maxFilesNum : 10,
//allowedFileTypes: ['image', 'video', 'flash'],
slugCallback : function(filename) {
return filename.replace('(', '_').replace(']', '_');
}
});
});
If anyone can help, I'm grateful.
this and upload method driver
@RequestMapping(value = REDIRECT_PAGE_UPLOAD, method = RequestMethod.GET)
public ModelAndView showUpload(ModelMap model, HttpServletRequest request) {
model.addAttribute(ControllerConstants.METHOD_NAME, RequestMethod.POST.name());
model.addAttribute(MODEL_NAME, new ItoBean(false));
model.addAttribute(HABILITAR_CAMPOS, true);
model.addAttribute(ControllerConstants.METHOD_NAME, RequestMethod.POST.name());
String action = String.join(SEPARATOR, request.getContextPath(), ACTION_UPLOAD);
model.addAttribute(ControllerConstants.ACTION, action);
return new ModelAndView(REQUEST_MAPPING_PAGE_UPLOAD);
}