I'm receiving the following Binary Stream from an HTTP request:
HTTP REQUEST
Document.get({id: $scope.documentId}, function(stream){
});
Angular Factory
.factory('Document', ['$resource', 'DOCUMENTS_CONFIG',
function($resource, DOCUMENTS_CONFIG) {
return $resource(DOCUMENTS_CONFIG.DETAIL_URL, {}, {
get: {
method: 'GET',
params: {},
url: DOCUMENTS_CONFIG.DETAIL_URL,
isArray: false
}
});
}
]);
Response
console.log(stream)
I need to convert this to a Uint8Array. I've tried to convert it to a bas64
// Convert Binary Stream To String
var dataString = JSON.stringify(stream);
// Convert to Base 64 Data
var base64Data = window.btoa(unescape(encodeURIComponent(dataString)));
When I run this I get an error 'malformed uri exception'. I've also tried window.btoa(dataString) but I get 'Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.'
How can I can convert this to an Uint8Array?