i have this simple form:
<form id="form">
<ul>
<li><label>Picture</label>
<input id="upload" name="Picture" class="k-textbox" data-bind="value: picture" type="file"/>
</li>
<li>
<label>Name</label>
<input type="text" data-bind="value: name" id="name" class="k-textbox" />
</li>
<li>
<label>Surname</label>
<input type="text" data-bind="value: surname" id="surname" class="k-textbox" />
</li>
</ul>
</form>
and my viewModel:
var ViewModel = funtion(){
this.picture = ko.observableArray();
this.name = ko.observable();
this.surname = ko.observable():
};
with knockout the var picture
contains only the path of the file, with kendo i can take the file with this code:
var kendoUpload = $("#upload").kendoUpload({
multiple: false,
});
var files = kendoUpload.data("kendoUpload").getFiles()[0];
i want send all my data to a java controller. I have try more controller...this is the last tri:
@RequestMapping(value = "addUser")
public String addUser(MultipartHttpServletRequest request, @RequestBody User user, @RequestParam("picture") MultipartFile[] uploadFiles)
throws Exception {
return "finish";
}
User is a simple class with String name, surname;
This is my ajax call:
$.ajax({
url : "./user/addUser",
type : "POST",
dataType :'multipart/form-data',
contentType : "application/json",
useProxy: false,
data : data
}).done(function(response) {
console.log(response);
});
What is the correct way to send my data and set the ajax call? How do I get the file uploaded through the data-bind of knockout and not by kendoUpload?