0
Well I’m having problems with this plugin would like to know if anyone has messed with it and if it could help in the question
I am having problems communicating with the controller I am taking the following error 405 Method Not Allowed, but only when using this plugin the other functions of my system as registration query are ok
follow my controller who receives the request
@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 that makes the post request 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 controller
@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);
}
opa then guy tried to leave the way you indicated put the error continues
– Wesley Santos
@Wesleysantos Error (405 Method Not Allowed) continues? I tested your code not using jQuery’s fileInput but with a Ubmit button in the form and it worked normally, another question: How is mapped the Requestmapping of the Controller where the method is upload
– Guilherme Pacheco
then the error persists I will edit and put the rest of my controller so you understand the whole context
– Wesley Santos
so if you could send me the example you created on top of my code so I can test
– Wesley Santos
@Wesleysantos with these variables in his code has no way I understand how the contexts are being mounted, try to validate if the path and the methods are hitting, because its implementation is correct
– Guilherme Pacheco
guy I tried to implement
– Wesley Santos
but still I keep making the error 405
– Wesley Santos