I want to extract EXIF data from remote images using Javascript. It works OK at the moment but it gets quite slow when the image is large since I download the entire image before extracting the EXIF data.
EXIF data is always within the first 128kb of an image (I believe) so I really don't need the entire image.
Is it possible to somehow only fetch the first XXX kb of a remote file with JS?
A range request works just fine:
$.ajax({ // assuming that you use jQuery
url: 'http://example.com/images/001.jpg',
headers: {
range: 'bytes=0-131071' // inclusive
},
complete: function (xhr) {
var data = xhr.responseText;
console.log(data.length); // 131072
console.log(xhr.status); // 206
yourExifParser(data);
}
});
Online demo: http://jsfiddle.net/9CknY/1/
But same-origin-policy applies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With