isaac lee
isaac lee

Reputation: 83

Can we detect when files begin to download in a Chrome Extension and can we access the local downloaded files?

I'm going to develop a Chrome Extension detecting status when files begin to download from chrome browser and read the files for certain purposes.

Upvotes: 4

Views: 3059

Answers (1)

Ishwar Kshirsagar
Ishwar Kshirsagar

Reputation: 21

  1. Store the download id.
let downloadIds = [];

chrome.downloads.onCreated.addListener(function (downloadItem) { 
    console.log("filename with absolute local path " , downloadItem.filename); // prints ""
    // Just FYI, you won't get downloadItem.filename here. So store the downloadId
    downloadIds.push(downloadItem.id);
});
  1. Get the filename by using following api. Use downloadId acquired from above step
chrome.downloads.search({id: downloadIds[0]}, function (downloadItem) {
        console.log("filename with absolute local path " , downloadItem.filename); 
        // prints "C:/user/downloads/yourfile"
    });

Now use <input type="file" > in your popup.html and access the file which match with your filename acquired from step

Upvotes: 2

Related Questions