VikasPushkar
VikasPushkar

Reputation: 432

Get Absolute path for downloaded file in chrome extension

I need absolute path for the files that i have downloaded through my chrome extension. this post mention a solution by using chrome.downloads.DownloadItem.filename but when i tried using the this, it gives me following error.

uncaught_exception_handler:8 Error in event handler for downloads.onDeterminingFilename: TypeError: Cannot read property 'filename' of undefined at chrome-extension:/background.js:165:51handler @ uncaught_exception_handler:8(anonymous function) @ uncaught_exception_handler:100EventImpl.dispatch_ @ event_bindings:376dispatchArgs @ event_bindings:243massage_determining_filename @ downloads:54dispatchEvent @ extensions::event_bindings:250

is chrome.downloads.DownloadItem.filename still being supported or i am doing something wrong?

Update:

**Permission in my manifest.json**
 "permissions": [
    "downloads",
    "tabs"  ]

background.js:

chrome.downloads.download({url:"http://myserver.com/123.html"},function (id){ 
    console.log( chrome.downloads.id.filename );
    LOG(id);});

Upvotes: 0

Views: 1195

Answers (1)

kzahel
kzahel

Reputation: 2785

The filename happens in a later callback. Look for the onProgress onChanged etc type chrome.download.* callbacks and in one of them the filename will appear.

Upvotes: 1

Related Questions