简体   繁体   中英

Get content of file when downloaded

I am building a Google Chrome extension to visualize some data stored in a csv files. I know this exists already with the webrequest API .

The problem is that sometimes the file is generated by a php page and no webrequest is send.

I've looked at the download API that listens to downloads. 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. It's not even possible to get access to such information through the webRequest API (it's a popular feature request though).

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). This method is unfortunately not very practical for non-GET (eg POST) request. 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM