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
  • 1
    Nice question!! Commented Nov 25, 2016 at 11:51

1 Answer 1

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:-

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.