简体   繁体   English

下载时获取文件内容

[英]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.

相关问题 通过代码获取下载的文件内容 - Get downloaded file content by code 如何获取单击某个文件时下载的文件的 url<div> 标签 - How to get the url of a file that is downloaded when clicking on a <div> tag 我想以谷歌浏览器扩展名访问下载的文件(在我的情况下为csv文件)并获取其内容 - I want to access downloaded file(csv file in my case) in google chrome extension and get content of that 无法访问下载的html文件的全部内容 - Unable to access the whole content of the downloaded html file 自动化:如何获取从 Web 浏览器下载的文件的下载路径 - Automation: How to get downloaded path of a file that was downloaded from the Web browser 即时通讯有一个textarea和HTML按钮。 当我单击按钮时,textarea内的任何内容都将以.DOCX文件的形式下载 - im having one textarea and button in html. when i click the button whatever content inside the textarea will be downloaded in the form of .DOCX file 获取下载文件的图像标签以显示 - Get image tag for downloaded file to display 在Android应用程序中获取下载的文件路径 - Get Downloaded File Path In Android Application 如何在文件夹中获取最近下载的文件 - How to get most recently downloaded file in a folder 如何获取用户插入的下载文件名? - How to get downloaded file name inserted by the user?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM