Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image to ArrayBuffer in Js

You need to get a jpg and convert to arrayBuffer, does anyone have any idea how to do this? I tried doing using a function below but without success for a Microsoft API

 document.querySelector('#inputImage').addEventListener('change', function() {

    var reader = new FileReader();
    reader.onload = function() {

      var arrayBuffer = this.result,
      array = new Uint8Array(arrayBuffer);


    };
like image 808
Adilmar Coelho Dantas Avatar asked Oct 28 '25 14:10

Adilmar Coelho Dantas


1 Answers

You can use this function to convert your base64 Image to an Array Buffer

export async function base64ToFile(dataURL, fileName) {
    const arr = dataURL.split(',');
    const mime = arr[0].match(/:(.*?);/)[1];
    return (fetch(dataURL)
        .then(function (result) {
            return result.arrayBuffer();
        }));
}
like image 124
Harish Soni Avatar answered Oct 31 '25 03:10

Harish Soni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!