I have a form with some text fields and a kendo upload control. I want the user to fill out the fields, select an image, then select a Save button at the end to save the information. I am having trouble sending the file data, it always comes through as null.
I'm going to simplify my code for the example but below is basically what I want:
SaveBasicInfo is called when the user clicks the Save button on the form. Here is the function on the server. The data all comes through except the rawData from the file. It ends up being NULL.
I tried both passing in a byte[] array and a string with the data, both I can't seem to get working. What is the proper way to pass the rawData to C# function so I can save the file to the database?
Thanks.
I'm going to simplify my code for the example but below is basically what I want:
$(document).ready(function () {
//kendo file upload control
$("#files").kendoUpload({
multiple: false,
select: onSelect
});
});
function onSelect(e) {
if (e.files[0] !== 'undefined') {
//has file
var myFile = e.files[0];
//save file to session if available
if (myFile.size > 0) {
if (HasLocalStorage()) {
//local storage available
sessionStorage.FileData = JSON.stringify(myFile.rawFile);
sessionStorage.FileName = myFile.name;
}
}
}
}
function BasicInfo(AccountId, AccountName, FileName, FileBinary) {
this.AccountId = AccountId;
this.AccountName = AccountName;
this.FileName = FileName;
this.FileBinary = FileBinary;
}
function SaveBasicInfo() {
//Get Info
var name = $("#txtName").val();
var accountid = $("#ddlAccount").val();
var FileName = '';
var FileBinary = null;
if (HasLocalStorage()) {
FileName = sessionStorage.FileName;
FileBinary = JSON.parse(sessionStorage.FileData);
var myBasicInfo = new BasicInfo(accountid, name, FileName, FileBinary);
$.ajax({
url: '/api/AM/BasicInfo/' + myUserInfo.CurrentAccountId,
type: 'put',
data: JSON.stringify(myBasicInfo),
contentType: 'application/json',
success: function (data) {
//Save was successful
},
error: function (err) {
alert(err.responseText);
},
complete: function () {
}
});
}
}
SaveBasicInfo is called when the user clicks the Save button on the form. Here is the function on the server. The data all comes through except the rawData from the file. It ends up being NULL.
public string PutBasicInfo(BasicInfo myBasicInfo) {
//Do Stuff Here
//myBasicInfo.FileBinary IS NULL!!
}
I tried both passing in a byte[] array and a string with the data, both I can't seem to get working. What is the proper way to pass the rawData to C# function so I can save the file to the database?
Thanks.