Our application downloads a zip file, but the answer is in binary format.
So, I did to convert it to base64. It works when the size 87.7KB, but an error occurs when the size of the response 183KB.
Error Uncaught RangeError: Maximum call stack size exceeded
Matching line
btoa(String.fromCharCode.apply(null, new Uint8Array(blob)))
In accordance with this answer String.fromCharCode.apply() must be replaced by TextEncoder.
So, I changed it to
btoa(new TextDecoder('utf-8').decode(new Uint8Array(blob)))
but I get an error.
Uncaught DOMException: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.
I changed it again using the topmost snippet of this.
New code now
btoa(unescape(encodeURIComponent(new TextDecoder('utf-8').decode(new Uint8Array(blob)))))
The download now works, but the download zip file is corrupt.
All code can be seen here.
source
share