I am writing an Angular/TypeScript app in Cordova that needs to download a binary file from a server.
Based upon another question, I could find out that I need to set an appropriate response type on the request parameters to prevent Angular from attempting to interpret the response body as JSON (which would lead to a crash, as it's binary data).
Answers in that question and the docs point me to Blob
and ArrayBuffer
as likely values.
Unfortunately, I cannot find any explanation on what is the difference between these two (no, the respective question has not really enlightened me), and both fail in their own ways.
ArrayBuffer
When using this, my app crashes with a RangeError
due to exceeding some maximum stack size deep down in the internals of Angular1.
Blob
With this, the request goes through, but unless I'm missing something, the debugger shows that I am only getting a small object withe blob size and the MIME type, but the actual binary data is missing!
What's more, the answer on the aforementioned question points out a TextDecoder
to "decode the result".
Can't I just get the binary response body as a byte array somehow?
1: That I actually have to extend this app that was started by another (more or less inaccessible to me) team, whose members added several layers of wrapping and parameter/result transformation around Angular's Http
service does not make things easier to debug, but I am pretty confident I have set my breakpoints at the bottommost level and am thus not experiencing any effects of the wrappers.