anki-connect/actions/media.md

143 lines
3.0 KiB
Markdown
Raw Normal View History

2020-05-25 00:23:37 +00:00
# Media Actions
* **storeMediaFile**
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.
Any existing file with the same name is deleted by default. Set `deleteExisting` to false to prevent that
by [letting Anki give the new file a non-conflicting name](https://github.com/ankitects/anki/blob/aeba725d3ea9628c73300648f748140db3fdd5ed/rslib/src/media/files.rs#L194).
2020-05-25 00:23:37 +00:00
*Sample request*:
```json
{
"action": "storeMediaFile",
"version": 6,
"params": {
"filename": "_hello.txt",
"data": "SGVsbG8sIHdvcmxkIQ=="
}
}
```
*Sample result*:
```json
{
"result": "_hello.txt",
2020-05-25 00:23:37 +00:00
"error": null
}
```
*Content of `_hello.txt`*:
```
Hello world!
```
*Sample request*:
```json
{
"action": "storeMediaFile",
"version": 6,
"params": {
"filename": "_hello.txt",
2020-12-12 16:41:01 +00:00
"path": "/path/to/file"
}
}
```
*Sample result*:
```json
{
"result": "_hello.txt",
"error": null
}
```
2020-05-25 00:23:37 +00:00
*Sample request*:
```json
{
"action": "storeMediaFile",
"version": 6,
"params": {
"filename": "_hello.txt",
"url": "https://url.to.file"
}
}
```
*Sample result*:
```json
{
"result": "_hello.txt",
2020-05-25 00:23:37 +00:00
"error": null
}
```
* **retrieveMediaFile**
Retrieves the base64-encoded contents of the specified file, returning `false` if the file does not exist.
*Sample request*:
```json
{
"action": "retrieveMediaFile",
"version": 6,
"params": {
"filename": "_hello.txt"
}
}
```
*Sample result*:
```json
{
"result": "SGVsbG8sIHdvcmxkIQ==",
"error": null
}
```
* **getMediaFilesNames**
Gets the names of media files matched the pattern. Returning all names by default.
*Sample request*:
```json
{
"action": "getMediaFilesNames",
"version": 6,
"params": {
"pattern": "_hell*.txt"
}
}
```
*Sample result*:
```json
{
"result": ["_hello.txt"],
"error": null
}
```
2020-05-25 00:23:37 +00:00
* **deleteMediaFile**
Deletes the specified file inside the media folder.
*Sample request*:
```json
{
"action": "deleteMediaFile",
"version": 6,
"params": {
"filename": "_hello.txt"
}
}
```
*Sample result*:
```json
{
"result": null,
"error": null
}
```