I have created a simple extension for use on a clients pc to add a save image option to the context menu. Googles Chrome extension documentation, plus examples quoted on the web, leads me to believe I can specify a subdirectory of the 'Downloads' folder as the download target, using 'filename' in the 'onDeterminingFilename' Event.
But I can't figure the syntax. Heres the listener with my pseudo code after 'filename':
chrome.downloads.onDeterminingFilename.addListener(function(item, suggest) {
suggest({filename: mysubdirectory + item.filename});
});
I've tried including mysubdirectory in quotes and with escaped characters, but with no change. The listener works as I've used filename: 'new name' to test it. I'm sure is very very simple, or maybe I've misunderstood the Event. Thanks.
I have created a simple extension for use on a clients pc to add a save image option to the context menu. Googles Chrome extension documentation, plus examples quoted on the web, leads me to believe I can specify a subdirectory of the 'Downloads' folder as the download target, using 'filename' in the 'onDeterminingFilename' Event.
But I can't figure the syntax. Heres the listener with my pseudo code after 'filename':
chrome.downloads.onDeterminingFilename.addListener(function(item, suggest) {
suggest({filename: mysubdirectory + item.filename});
});
I've tried including mysubdirectory in quotes and with escaped characters, but with no change. The listener works as I've used filename: 'new name' to test it. I'm sure is very very simple, or maybe I've misunderstood the Event. Thanks.
Share Improve this question asked Feb 10, 2014 at 13:31 user3292967user3292967 1411 silver badge5 bronze badges1 Answer
Reset to default 11I'd used the wrong quote marks.
This works:
chrome.downloads.onDeterminingFilename.addListener(function(item, suggest) {
suggest({filename: "mysubdirectory/" + item.filename});
});
If mysubdirectory is not present it's created. If it is present, the item is added, plus any other items downloaded. Happy days.