View Source AnkiConnect.Specs.FileSpec (anki_connect v0.1.1)

Includes type specs for file.

Link to this section Summary

Types

t()

Represents a file to be downloaded by Anki to media folder.

Link to this section Types

@type t() ::
  %{
    data: String.t(),
    filename: String.t(),
    skip_hash: String.t() | nil,
    fields: [String.t()] | nil
  }
  | %{
      path: String.t(),
      filename: String.t(),
      skip_hash: String.t() | nil,
      fields: [String.t()] | nil
    }
  | %{
      url: String.t(),
      filename: String.t(),
      skip_hash: String.t() | nil,
      fields: [String.t()] | nil
    }

Represents a file to be downloaded by Anki to media folder.

You can specify a base64-encoded string with data param, an absolute file path with path, or a url with url param 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.

example-base64-encoded

Example (base64 encoded):

%{
  filename: "_hello.txt",
  data: "SGVsbG8sIHdvcmxkIQ=="
}

example-absolute-path

Example (absolute path):

%{
  filename: "_hello.txt",
  path: "/path/to/file"
}

example-url

Example (URL):

%{
  filename: "_hello.txt",
  url: "https://url.to.file"
}

The optional skip_hash field can be optionally provided to skip the inclusion of files with an MD5 hash that matches the provided value. This is useful for avoiding the saving of error pages and stub files.

The optional fields member is a list of fields that should play audio or video, or show a picture when the card is displayed in Anki.

example

Example:

%{
  url: "https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?kanji=猫&kana=ねこ",
  filename: "yomichan_ねこ_猫.mp3",
  skip_hash: "7e2c2f954ef6051373ba916f000168dc",
  fields: ["Front"]
}