I'd like to use Exif.js to read JPEG EXIF tags from a local file. However, the javascript lib uses XMLHttpRequest
to read JPG files as a BinaryFile
:
function getImageData(oImg, fncCallback)
{
BinaryAjax(
oImg.src,
function(oHTTP) {
var oEXIF = findEXIFinJPEG(oHTTP.binaryResponse);
oImg.exifdata = oEXIF || {};
if (fncCallback) fncCallback();
}
)
}
When I use <input type="file">
I get an HTML5 File
object which I can read using a FileReader
but I don't know how to convert this to a BinaryFile
:
_initHTML5FileReader = function() {
var chooseFile;
chooseFile = document.getElementById("html5-get-file");
chooseFile.onchange = function(e) {
var file;
file = e.currentTarget.files[0];
var reader;
reader = new FileReader();
reader.onloadend = function(ev) {
var dataUrl = ev.target.result;
// How do I change this to a BinaryFile???
};
reader.readAsDataURL(file);
return false;
};
};
But I also using AppGyver Steroids (PhoneGap) which serves my page from http://localhost/index.html
, and when I try to use Exif.js, I get this CORS error:
XMLHttpRequest cannot load data:image/jpeg;base64,/9j/4X2cRXhpZgAASUkqAAgAAAAOAA8BAgAKAAAAtgAAABABAgAI…N6gn14dm6BmJyMdYaMhX16hI+HgIWLj5aWkJOaiHF7hoV+dnBwc3Jzbm14hGlZcIaWlXFEU3OB. Received an invalid response. Origin 'http://localhost:4000' is therefore not allowed access.
Is there any way to configure XmlHttpRequest to serve a local File object without the CORS error?