Open cpetrov opened 2 years ago
Most of this is already possible with Tabris. Constructing the data URL string requires a btoa
polyfill like abab
and knowledge of the media type though.
const arrayBuffer = await blob.arrayBuffer();
const binaryString = await blobToBinaryString(blob);
const textString = await blob.text();
const dataUrlString = 'data:<my-media-type>;base64,' + btoa(await blobToBinaryString(blob));
async function blobToBinaryString(blob) {
const ab = await blob.arrayBuffer();
return new Uint8Array(ab).reduce((data, byte) => data + String.fromCharCode(byte), '')
}
Feature description
The FileReader API enables conversion of
Blobs
intoArrayBuffer
, binary and text strings and data URLs. It is particularly useful when serializing data for exchange with external services.Proposed solution
Implement the FileReader API.