【发布时间】:2013-05-18 16:57:15
【问题描述】:
我正在尝试使用文件 API 库 (https://github.com/mailru/FileAPI) 作为不支持文件 API 的浏览器的后备,以便将文件作为数据 URL 读取并将其传递给另一个函数。
我有这个代码:
function handleFileSelect(event) {
// If supported, use native File API.
if(window.FileReader != null) {
console.log('Using native File API.'); // !
var files = event.target.files;
for(var i = 0, f; f = files[i]; i++) {
var reader = new FileReader();
reader.onload = function(event) {
insertImage(event.target.result);
};
reader.readAsDataURL(f);
}
}
// Otherwise, use fallback polyfill for browsers not supporting native API.
else {
console.log('Using polyfill for File API.'); // !
var file = FileAPI.getFiles(event.target);
FileAPI.readAsDataURL(file, function(evt) {
console.log(evt);
});
}
}
但是,console.log(evt) 返回一个报告错误的对象:“filereader_not_support_DataURL”。
我是否在使用 File API polyfill 时做错了什么,或者是否需要使用 shim 或其他 polyfill 才能使数据 URL 正常工作?
谢谢。
-- 山姆。
【问题讨论】:
标签: javascript html fileapi polyfills