我正在使用 ClipboardData API 在浏览器应用程序中实现复制粘贴功能,as explained in this answer.
FileReader::readAsDataURL(blob)
提供了文件数据的异步读取,这很棒。
var items = (event.clipboardData || event.originalEvent.clipboardData).items;
var reader = new FileReader();
reader.onload = function(event){
/*add item (i.e. image) to page*/}; //callback
var blob = items[0].getAsFile(); //not async
reader.readAsDataURL(blob); //async
问题:
1) 有没有办法使 DataTransferItem::getAsFile()
方法异步?
2) 有没有办法让 FileReader
将 DataTransferItem
作为参数,这样它就可以像处理 blob 一样执行 async
本身?
3) 我运气不好吗?
最佳答案
Is there a way to make the DataTransferItem::getAsFile() method asynchronous?
没有。 It's specified作为同步。但是,绝对没有理由使其成为异步的 - 对文件的引用是快速构建的,并且不包含任何数据挖掘。正如 input.files
同步获取对尚未读入文件的引用一样。
Is there a way to get
FileReader
to take aDataTransferItem
as an argument so it can do the async itself like it does already with blobs?
没有。它只接受 item.getAsFile()
blob,并且可以异步读取它。
关于javascript - HTML5 和 JavaScript : How do I make paste handling fully/more asynchronous?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21669176/