I am uploading an image file to .net MVC controller using javascript and AJAX POST call. But the problem is--
1) I am getting size of file in javscript using this
var FileSize = $('#ProfilePicUpload')[0].files[0].size;
When I send it to controller it doesnot receive any data in byte datatype. Instead it goes either in string or int or long datatype.
1)I've used jquery to get the size of image using files[0].size
. I successfully get the size of uploaded image.
2)I also set content-type: 'application-json/UTF-8'
. and processData:false
and contentType:false
.
But this results in string[] OfficialData to 0 on controller side.
3)I am receving rest of form data in string[] on controller side and only image size in byte[] format
//OfficialData.js file
var FileSize = $('#ProfilePicUpload')[0].files[0].size; //get size of image file.
//ajax call
$.ajax({
type: "POST",
url: "/Employee/AddEmployeeOfficialDetail",
data: { "OfficialData": Employee_Data, size: FileSize },
success: function (data) {
if (data.check === -1) {
jAlert("Employee Already Exists!", "Alert", function () {});}
//controller code
public async Task<IActionResult> AddEmployeeOfficialDetail(string[] OfficialData,byte[] size)
{
Employee.fileContents.FileSize = BitConverter.GetBytes(size);
}
I get byte[] size = null
If I use int then I get size of image File like int size = 34598.
My only requirement is to get exactly the size of Image from java-script from ajax call to byte[] on controller side.