2

I want to read this png in binary format.

I have been reading all over the net, and this looks like the correct way of doing it with angular.

But it just does not work. Any idea why?

 $http({
                url: 'somepng.png',
                method: 'GET',
                data: '',
                responseType: 'arraybuffer'
            }).success(function(resp, config1, config2, config3) {
                console.log(typeof resp); // this is a string, weird! in Chrome
                console.log(resp);
            });

The arrray buffer returns a string instead of an array o of bytes.

Dany D
  • 1,189
  • 2
  • 18
  • 44
  • 1
    Try to take a look at http://stackoverflow.com/questions/16791295/how-to-read-binary-data-in-angularjs-in-an-arraybuffer – Whisher Dec 12 '14 at 16:25
  • Whisher, this uses the example exactly like in the post you gave me. – Dany D Dec 12 '14 at 17:19
  • Adding the `responseType: "arraybuffer"` to the config worked for me, as proposed in the answer linked to by @Whisher. – vadipp Nov 09 '15 at 09:45

1 Answers1

1
var config = {headers: {
            'Accept': "image/png"
        }
    };
$http.get('somepng.png', config).success(successCallback).error(errorCallback);

this answer is the changed one....