1

Hello Everyone I am using angularjs to send byte array on server side but I am not getting data on server side. Here is my code.

$scope.Upload = function () {
    var bytesToSend = [253, 0, 128, 1]
    var send = new Uint8Array(bytesToSend)
    var Upload = $.ajax({
        type: 'POST',
        url: "/UploadFile",
        dataType: JSON,
        contentType: false,
        data: send,
        success: function (send) {
            toastr.success("Upload Successfully");
        }
    });
    Upload.error(function () { console.log(bytesToSend+'gaurav') });

}

And here is my server side code

 [HttpPost]
        [Route("UploadFile")]
        public  bool UploadedFile(byte[] send)
        {

            return false;
            //return await CenterGateWay.UpldFile(up);

        }
    }

I am not getting data in byte[] send it is showing null value. please anyone help where I am wrong And I am getting data in console here [253, 0, 128, 1]. Using firefox browser right now.

1 Answers1

0

Please use following code to resolve your issue.

 $scope.Upload = function () {
    var bytesToSend = [253, 0, 128, 1];
    var send = new Uint8Array(bytesToSend)
    var Upload = $.ajax({
        type: 'POST',
        url: "/Home/UploadFile",
        dataType: "JSON",
        data: { send: btoa(String.fromCharCode.apply(null, send)) },
        success: function (send) {
            toastr.success("Upload Successfully");
        }
    });

    Upload.error(function () { console.log(bytesToSend + 'gaurav') });
}

In Controller

 [HttpPost]
 [Route("UploadFile")]
 public  bool UploadedFile(string send)
 {
     return false;
     //return await CenterGateWay.UpldFile(up);
 }

Even I got help from this link Please refer it:-

Community
  • 1
  • 1
J-Mean
  • 1,192
  • 1
  • 8
  • 14