I've read through a dozen posts on how to convert between ArrayBuffer to Blob or to Uint8Array etc. before sending the data to the client side... but I can't seem to be able to get it to work at all. When I do get the data through, I was not able to reconstruct them back as a Blob before outputting it to a file..
const Blob = require('cross-blob'); const randomBytes = require('randombytes'); const buffer = randomBytes(1024); // Supposed to give me Buffer The followings were the stuff I tried...
data = buffer; ^ gives me <Buffer 11 22 33 ...>
data = Uint8Array.from(buffer); ^ gives me an array of integer, this looked the most promising? but when arrived to the client side, it became an object with indexes and byte value...
data = Uint8Array.from(buffer).buffer; ^ gives ArrayBuffer { byteLength: 1024}, when inspect it shows size: 2 and type: 'text/plain'...
data = new Blob(buffer, { type: 'application/octet-stream' }); data = new Blob([new Uint8Array(buffer, buffer.byteOffset, buffer.length)], { type: 'application/octet-stream' }); data = new Blob([Uint8Array.from(buffer)], { type: 'application/octet-stream' }); ^ all these, when arrived to the client side also with size: 2 and type: 'text/plain'...
On the server side, I am running Express:
router.get('/test/*', function(req, res, next) { ... let data = myFunctionThatGeneratesData(); res.send(data); }); On the client side, I'm requesting it like this (Angular/TypeScript):
this.http.get('/test/random-bytes-array', { responseType: 'blob' // also tried 'arraybuffer' }).subscribe(data => { debugger; console.log(data); }); I must be doing something wrong... I am trying to send multiple chunk of binary data over, either as an ArrayBuffer, Uint8Array or Blob (whatever works) and when arriving at the other end, combine them back into a Blob.