我想使用Exif.js从本地文件中读取JPEG EXIF标记。但是,javascript lib使用XMLHttpRequest
将JPG文件作为BinaryFile
:
function getImageData(oImg, fncCallback)
{
BinaryAjax(
oImg.src,
function(oHTTP) {
var oEXIF = findEXIFinJPEG(oHTTP.binaryResponse);
oImg.exifdata = oEXIF || {};
if (fncCallback) fncCallback();
}
)
}
当我使用<input type="file">
时,我会收到一个HTML5 File
对象,我可以使用FileReader
阅读该对象,但我不知道如何将其转换为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;
};
};
但是我也使用AppGyver Steroids(PhoneGap)从http://localhost/index.html
提供我的页面,当我尝试使用Exif.js时,我收到此CORS错误:
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.
有没有办法配置XmlHttpRequest来提供没有CORS错误的本地File对象?