-1

When I am sending blob to server but when i am sending it back to client using emit() of socketio library it is converted to ArrayBuffer(2563)

[[Int8Array]]
:
Int8Array(2563) [100, 105, 115, 116, 114, 105, 98, 117, 116, 105, 111, 110, 32, 118, 115, 32, 118, 97, 114, 97, 98, 108, 105, 116, 121, 32, 32, 111, 114, 32, 115, 116, 97, 110, 100, 97, 114, 100, 32, 100, 101, 118, 105, 97, 116, 105, 111, 110, 13, 10, 13, 10, 13, 10, 115, 99, 97, 108, 101, 32, 111, 102, 32, 115, 99, 97, 116, 116, 101, 114, 32, 112, 108, 111, 116, 13, 10, 108, 105, 110, 110, 101, 114, 32, 112, 97, 116, 116, 101, 114, 32, 111, 102, 32, 108, 105, 110, 101, 32, 105, …]

[[Uint8Array]]
:
Uint8Array(2563) [100, 105, 115, 116, 114, 105, 98, 117, 116, 105, 111, 110, 32, 118, 115, 32, 118, 97, 114, 97, 98, 108, 105, 116, 121, 32, 32, 111, 114, 32, 115, 116, 97, 110, 100, 97, 114, 100, 32, 100, 101, 118, 105, 97, 116, 105, 111, 110, 13, 10, 13, 10, 13, 10, 115, 99, 97, 108, 101, 32, 111, 102, 32, 115, 99, 97, 116, 116, 101, 114, 32, 112, 108, 111, 116, 13, 10, 108, 105, 110, 110, 101, 114, 32, 112, 97, 116, 116, 101, 114, 32, 111, 102, 32, 108, 105, 110, 101, 32, 105, …]
byteLength
:
(...)

I have upload text file send to server and in console this was file return by server, so how to read the file content, I have used filereader API and converted it to blob and then server has send it to me as arraybuffer.

when file was in file I was able to read its content directly on client side when I send it to server in python the blob file I was able to read it too, by print but when it was send back to client arraybuffer, I don't know how to view its content.

Prashant Pimpale
  • 10,349
  • 9
  • 44
  • 84
green seek
  • 133
  • 3
  • 11

1 Answers1

0

You can make a Blob from an ArrayBuffer, you can then run that Blob through FileReader to get the text

var blob = new Blob([yourArrayBuffer]);
var reader = new FileReader();
reader.onloadend = function(){
  console.log("text: ",reader.result);
};
reader.readAsText(blob);
Patrick Evans
  • 41,991
  • 6
  • 74
  • 87