Skip to content

Instantly share code, notes, and snippets.

@AshKyd
Created January 10, 2024 02:23
Show Gist options
  • Save AshKyd/0b3eb5105b736e8935274d3e983445c1 to your computer and use it in GitHub Desktop.
Save AshKyd/0b3eb5105b736e8935274d3e983445c1 to your computer and use it in GitHub Desktop.
function dataTransferItemToArrayBuffer(dataTransferItem){
return new Promise((resolve, reject) => {
if(dataTransferItem.kind !== 'file') {return reject(new Error('DataTransferItem is not of kind "file"'));}
const file = dataTransferItem.getAsFile();
var reader = new FileReader();
reader.onload = function() {
var arrayBuffer = this.result,
array = new Uint8Array(arrayBuffer);
resolve(arrayBuffer);
}
reader.onerror = reject;
reader.readAsArrayBuffer(file);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment