Home » Jquery » How to get an image filesize (in bytes) from any domain using JavaScript / jQuery-Exceptionshub

How to get an image filesize (in bytes) from any domain using JavaScript / jQuery-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

ok, I have searched for this and found few solutions, but none seems to work. Note hat the solution must work all the time across all major browsers and not be affected by that cross origin restriction. Here is the well-known generic code to get the image width and height once it has been downloaded completely and set to the image object:

   const imageUrl = 'https://helpx.adobe.com/content/dam/help/en/stock/how-to/visual-reverse-image-search/jcr_content/main-pars/image/visual-reverse-image-search-v2_intro.jpg';

   var img = new Image();

    img.onload = function() {
        alert( this.width + ' '+ this.height);
    };

    img.src = imageUrl;

The expected value for that image should be an image filesize of 224,662 bytes.

I have changed the image URL to one where we encounter a CORS issue.

How to&Answer: