diff --git a/actions/media.md b/actions/media.md index 8c534bd..2874a60 100644 --- a/actions/media.md +++ b/actions/media.md @@ -2,10 +2,8 @@ * **storeMediaFile** - Stores a file with the specified base64-encoded contents inside the media folder. alternatively you can specify a - url from where the file shell be downloaded. If both field `data` and `url` are provided, the `data` field will be - used. To prevent Anki from removing files not used by any cards (e.g. for configuration files), prefix the filename - with an underscore. These files are still synchronized to AnkiWeb. + Stores a file with the specified base64-encoded contents inside the media folder. Alternatively you can specify a + absolute file path, or a url from where the file shell be downloaded. If more than one of `data`, `path` and `url` are provided, the `data` field will be used first, then `path`, and finally `url`. To prevent Anki from removing files not used by any cards (e.g. for configuration files), prefix the filename with an underscore. These files are still synchronized to AnkiWeb. *Sample request*: ```json @@ -32,6 +30,26 @@ Hello world! ``` + *Sample request*: + ```json + { + "action": "storeMediaFile", + "version": 6, + "params": { + "filename": "_hello.txt", + "file": "/path/to/file" + } + } + ``` + + *Sample result*: + ```json + { + "result": null, + "error": null + } + ``` + *Sample request*: ```json { diff --git a/plugin/__init__.py b/plugin/__init__.py index 5fa9030..8de44af 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -471,10 +471,15 @@ class AnkiConnect: @util.api() - def storeMediaFile(self, filename, data=None, url=None): + def storeMediaFile(self, filename, data=None, path=None, url=None): if data: self.deleteMediaFile(filename) self.media().writeData(filename, base64.b64decode(data)) + elif file: + self.deleteMediaFile(filename) + with open(path, 'rb') as f: + data = f.read() + self.media().writeData(filename, data) elif url: self.deleteMediaFile(filename) downloadedData = util.download(url)