2

I have a byte array with some data in it. Now I want it to send the array in a RAW/Binary format to my embedded webserver:

var array = new Uint8Array(317);
... inserting data into array ... 

$http.post('http://api/write_file', array)          
        .then(function(response) {
            //Success
        },function(response) {
            //Fail..
    });

Problem is that AngularJS by default sends the array as JSON - anyway to change this? I just want it to be transmitted raw!

EDIT:

I've tried to overwrite the transformRespons:

    $http({
      url: 'http://api/write_file',
      method: 'POST',
      transformResponse: function(value) {
        return value; //Just return the value, without transform.. 
      },
      data: array
    }).then(function(response) {
             //Success
    },function(response) {
             //Fail
    });

But no luck? it sends exactly the same JSON as before.

Jolle
  • 1,336
  • 5
  • 24
  • 36
  • I usually use FormData to send binary information. Then just [send the form data](https://stackoverflow.com/questions/11442632/how-can-i-post-data-as-form-data-instead-of-a-request-payload) – ryanyuyu Nov 13 '15 at 13:45
  • Under the header 'Overriding the Default Transformations Per Request' on this page https://docs.angularjs.org/api/ng/service/$http it looks like you can override the default 'transformResponse' property. – Robert Corey Nov 13 '15 at 13:46

0 Answers0