FileReader.readAsDataURL or Blob.arrayBuffer for a browser file?
Read one three-byte Blob through both browser APIs. See exactly which result suits an image preview, a checksum or a Base64 JSON field.
Start with the consumer of the result
For an image src, FileReader.readAsDataURL() supplies both the media type and the encoded data in a string. For inspecting bytes or computing a checksum, Blob.arrayBuffer() gives you binary storage. A File supplied by a file picker supports the Blob methods too.
Read one Blob in the browser console
This example creates its own file contents. One operation prints data:application/octet-stream;base64,AP9B and the other prints [0, 255, 65]. Both reads are asynchronous, so do not rely on the order in which the messages appear.
const file = new Blob([Uint8Array.of(0, 255, 65)], {type: "application/octet-stream"});
const reader = new FileReader();
reader.addEventListener("load", () => console.log(reader.result));
reader.readAsDataURL(file);
file.arrayBuffer().then(buffer => console.log(Array.from(new Uint8Array(buffer))));Match the upload field
For an API expecting raw Base64, take AP9B after the first comma in the data URL once the load event fires. An endpoint accepting binary uploads may accept the File or Blob directly. Read the upload contract before converting a preview string into a request body.