ReadAsDataURL()不起作用 [英] ReadAsDataURL() doesn't work
本文介绍了ReadAsDataURL()不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在我的网站中实现拖放"功能. 我需要将拖放的图像转换为数据URI,以便可以与JCrop一起使用并在之后上传.
I was trying to implement a Drag n' Drop feature in my website. I need to convert the dropped image into Data URI so I can use it with JCrop and upload it after.
drop: function (e) {
e = e || window.event;
e.preventDefault();
e = e.originalEvent || e;
var files = (e.files || e.dataTransfer.files);
var reader = new FileReader();
reader.onload = function (event){
console.log(event.target.result);
};
reader.readAsDataURL(files);
return false;
}
但是控制台中没有任何显示.甚至没有undefined
. files
变量返回带有我放下的图像的对象FileList,因此问题不存在.我怎样才能解决这个问题? :(
But nothing shows up in the console. Not even undefined
. The files
variable returns an Object FileList with the image I dropped, so the problem is not there. How can I fix this? :(
推荐答案
//applies to only one file.
reader.readAsDataURL(files);
解决方案:
for(var i=0;i<files.length;i++){
reader.readAsDataURL(files[i]);
}
这篇关于ReadAsDataURL()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文