Polyjuice Client v0.4.4 Polyjuice.Client.Media View Source

Media-related functions.

Link to this section Summary

Functions

Download a file from the media repository.

Upload a file to the media repository.

Link to this section Functions

Link to this function

download(client_api, url, filename \\ nil, allow_remote \\ true)

View Source
download(
  client_api :: Polyjuice.Client.API.t(),
  url :: String.t() | URI.t() | {String.t(), String.t()},
  filename :: String.t() | nil | boolean(),
  allow_remote :: boolean()
) :: {:ok, String.t(), String.t(), Enumerable.t()} | any()

Download a file from the media repository.

url may be either a binary or a URI (giving an mxc:// URI to download), or a {server_name, media_id} tuple. filename is an (optional) filename to request that the server use, and allow_remote indicates whether the server should fetch media from remote servers if necessary (defaults to true).

If successful, returns a tuple of the form {:ok, filename, content_type, body}, where body is a Stream such that Enum.join(body) is the file contents.

Link to this function

upload(client_api, data, opts \\ [])

View Source
upload(
  client_api :: Polyjuice.Client.API.t(),
  data :: binary() | {:file, String.t()},
  opts :: Keyword.t()
) :: {:ok, String.t()} | any()

Upload a file to the media repository.

data may be either a binary, indicating the file contents, or a tuple {:file, path}, where path is a path to the file to be uploaded.

opts is a keyword list of options. Recognized options are:

  • filename: the filename to use for the uploaded file. This is required when data is a binary. If not specified, and data is of the form {:file, path}, then the filename defaults to the basename of the path.
  • mimetype: the mimetype to use for the uploaded file. Defaults to application/octet-stream.