I’m trying to use an extension to download files automatically. Per chrome.downloads API it’s possible to set a folder to download the file inside a new folder inside downloads folder:
The DownloadItem’s new target DownloadItem.filename, as a path
relative to the user’s default Downloads directory, possibly
containing subdirectories. Absolute paths, empty paths, and paths
containing back-references “..” will be ignored. filename is ignored
if there are any onDeterminingFilename listeners registered by any
extensions.
The problem is that when I try to download the file to test/filename.jpg
folder, nothing happens. If I remove the folder name and let only filename.jpg
it downloads as supposed to the main download folder. The following code doesn’t work:
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "downloadfile") {
var bread1 = document.getElementsByClassName('c-breadcrumb__link')[1].innerHTML
const filename = "hoge.jpg";
const url = "image_url";
chrome.downloads.download({
filename: bread1 + "" + filename,
url: url,
conflictAction: overwrite,
});
}
});
This one works without problem:
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "downloadfile") {
//var bread1 = document.getElementsByClassName('c-breadcrumb__link')[1].innerHTML
const filename = "hoge.jpg";
const url = "image_url";
chrome.downloads.download({
filename: filename,
url: url,
conflictAction: overwrite,
});
}
});
I want to automatically sort all the downloads within subfolders by the filename.
This does not work even if I create the folder manually.
Already tried with slash and backslash and even added a slash/backslash in the main folder also.
I know that usually, you can’t create folders with JS, but I want to test if this API can create a subfolder in Chrome “Downloads” folder, but since it doesn’t even work if I create the folder manually, it seems something went wrong.
If anyone knows that isn’t possible even using this API, what would be the best way to achieve the folder creation process automatically to sort and place the files inside their own folder?