Add file parameter to storeMediaFile (#208)
This commit is contained in:
parent
06dff21107
commit
08f0d0cb7e
@ -2,10 +2,8 @@
|
|||||||
|
|
||||||
* **storeMediaFile**
|
* **storeMediaFile**
|
||||||
|
|
||||||
Stores a file with the specified base64-encoded contents inside the media folder. alternatively you can specify a
|
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
|
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.
|
||||||
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.
|
|
||||||
|
|
||||||
*Sample request*:
|
*Sample request*:
|
||||||
```json
|
```json
|
||||||
@ -32,6 +30,26 @@
|
|||||||
Hello world!
|
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*:
|
*Sample request*:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
@ -471,10 +471,15 @@ class AnkiConnect:
|
|||||||
|
|
||||||
|
|
||||||
@util.api()
|
@util.api()
|
||||||
def storeMediaFile(self, filename, data=None, url=None):
|
def storeMediaFile(self, filename, data=None, path=None, url=None):
|
||||||
if data:
|
if data:
|
||||||
self.deleteMediaFile(filename)
|
self.deleteMediaFile(filename)
|
||||||
self.media().writeData(filename, base64.b64decode(data))
|
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:
|
elif url:
|
||||||
self.deleteMediaFile(filename)
|
self.deleteMediaFile(filename)
|
||||||
downloadedData = util.download(url)
|
downloadedData = util.download(url)
|
||||||
|
Loading…
Reference in New Issue
Block a user