【发布时间】:2013-09-24 12:24:24
【问题描述】:
我正在使用 HTML5 File API & FileReader。
HTML:
<div id="holder"></div>
JS:
<script>
var holder = document.getElementById('holder'),
state = document.getElementById('status');
if (typeof window.FileReader === 'undefined') {
state.className = 'fail';
} else {
state.className = 'success';
state.innerHTML = 'File API & FileReader available';
}
holder.ondragover = function () { this.className = 'hover'; return false; };
holder.ondragend = function () { this.className = ''; return false; };
holder.ondrop = function (e) {
this.className = '';
e.preventDefault();
var file = e.dataTransfer.files[0],
reader = new FileReader();
reader.onload = function (event) {
console.log(event.target);
holder.style.background = 'url(' + event.target.result + ') no-repeat center';
};
console.log(file);
reader.readAsDataURL(file);
return false;
};
</script>
如何从上传的图片中检索 EXIF 元数据?
我尝试使用this。
HTML:
<img src="image1.jpg" id="img1" exif="true" />
JS:
console.log($("#img1").exifPretty());
这只会返回一个空集。
当我使用加载函数时,我得到一个文件,它是原始 File 对象的扩展名。
on:
load: function(e, file) { }
但是如何从中检索 EXIF 元数据?
【问题讨论】:
-
@Andreas 我使用 FileReader JQuery 插件来检索文件:github.com/bgrins/filereader.js 我有一个文件对象,但我无法获取元数据。请参阅我的问题更新。可以发个答案吗?
-
在您的示例中,您没有使用 FileReader 插件,所以您是否尝试过链接 SO 问题的解决方案?使用
FileReader中的.readAsBinaryString,将此字符串包装到BinaryFile(包含在EXIF库中)将此对象提供给EXIF.readFromBinaryFile(binaryFileObject)
标签: javascript jquery html filereader