Skip to content Skip to sidebar Skip to footer

How To Pass Images From Server To Function In Javascript?

I'm trying to pass images to function in JS that extracts metadata. Said images are kept in folder on server(localhost for now). I got the function to work with file input from HTM

Solution 1:

Wherever you have e.tartget.files[0], replace it with an Image. You make the image like this:

var myImage = new Image();
myImage.src = 'https://www.gstatic.com/images/branding/googlelogo/2x/googlelogo_color_284x96dp.png';

So you would replace e.tartget.files[0] with myImage. Then obviously change the url to the file.. ie http://localhost/pics/image.jpg


If you're having problems with it working intermittently, you may have a race condition. Solve it by throwing your logic in the onload function...

var myImage = newImage();
myImage.src = 'https://www.gstatic.com/images/branding/googlelogo/2x/googlelogo_color_284x96dp.png';
myImage.onload = function(){ 
    EXIF.getData(myImage, function (){
        // exif stuff here...
    }
};

Post a Comment for "How To Pass Images From Server To Function In Javascript?"