chrm
chrm

Reputation: 1288

Problematic characters for filename in chrome.downloads.download

Using certain characters in the filename argument to the function chrome.downloads.download leads to an "Invalid filename" error, when starting the download. I can't find any information in the documentation and replacing for example : with %3A or &#58 ; doesn't work.

The problematic characters are:

: " ? ~ < > * |

Here is an example you can use in the background page console from any extension with the downloads permission.

chrome.downloads.download(
    {url: "http://i.imgur.com/3cWNMt3.webm",
     filename: "title:subtitle.webm"},
    function (downloadId) {
        if (downloadId===undefined)
            console.log(chrome.runtime.lastError);
        else
            console.log("Ok");
});

Is there a way to use these problematic characters?

Edit: Is there a list for the characters chrome.downloads.download doesn't support?

Edit 2: To put it another way. The user can manually download a file in Chrome (Linux) and, in the download dialog, name it:

title:subtitle.extension

I would like to do the same in my extension.

This filename is just an example, the filenames get generated automatically depending on the webpage and some user generated rules.

Upvotes: 8

Views: 5756

Answers (1)

Xan
Xan

Reputation: 77531

Is there a way to use these problematic characters?

No. That would be an invalid filename.

What exactly is invalid varies by OS. Here's a full ruleset for Windows.

A common strategy is to replace the characters with something allowed; for example, _

See also this question.

Upvotes: 4

Related Questions