[英]Get content of file when downloaded
I am building a Google Chrome extension to visualize some data stored in a csv files. 我正在构建Google Chrome扩展程序,以显示存储在csv文件中的一些数据。 I know this exists already with the webrequest API .
我知道这已经存在于webrequest API中 。
The problem is that sometimes the file is generated by a php page and no webrequest is send. 问题是有时文件是由php页面生成的,没有webrequest发送。
I've looked at the download API that listens to downloads. 我查看过监听下载的下载API 。 I am now able to know when a download is done.
我现在能够知道下载完成的时间。
My question is: 我的问题是:
Can I access to the content of a file that has been downloaded, or that is being downloaded? 我可以访问已下载或正在下载的文件的内容吗?
. 。
Here is a code sample 这是一个代码示例
chrome.downloads.onChanged.addListener(function(currentFile) {
console.log(currentFile)
// I would need to get the content of currentFile here.
});
It's not possible to get the contents of a downloaded file with a Chrome extension. 无法通过Chrome扩展程序获取下载文件的内容。 It's not even possible to get access to such information through the
webRequest
API (it's a popular feature request though). 甚至无法通过
webRequest
API访问此类信息(尽管这是一个受欢迎的功能请求 )。
Usually, if you want the response body, you have to send a new request to the server (and hope that Chrome is getting the data from the cache). 通常,如果您需要响应正文,则必须向服务器发送新请求(并希望Chrome从缓存中获取数据)。 This method is unfortunately not very practical for non-GET (eg POST) request.
遗憾的是,对于非GET(例如POST)请求,该方法不太实用。 There is no general way to solve this problem.
没有通用的方法来解决这个问题。
If you wish to get access to the response body, you have to develop a solution specific to your application, eg something that intercepts all POST requests for a particular page, and send the data back to the user (in order to save the file). 如果您希望访问响应正文,则必须开发特定于您的应用程序的解决方案,例如拦截特定页面的所有POST请求,并将数据发送回用户(以便保存文件) 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.