[Edit]
+
0
-
0

JavaScript - convert blob to text (from UTF-8 bytes)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
function readText(blob, callback) { if (window.FileReader) { var reader = new FileReader(); reader.onload = function() { callback(reader.result, null); }; reader.onerror = function() { callback(null, 'Incorrect blob or file object.'); }; reader.readAsText(blob, 'UTF-8'); } else { callback(null, 'File API is not supported.'); } } // Usage example: const blob = ... // Hint: File is Blob so we can convert read file as text. readText(blob, function(text, error) { if (!error) { // Put `text` variable usage here ... } }); // See also: // // 1. https://dirask.com/snippets/JavaScript-convert-text-to-Blob-text-plain-and-UTF-8-encoding-DlBN4j