exfile v0.3.6 Exfile.Backend behaviour View Source

Represents a backend that stores files.

Link to this section Summary

Functions

Deletes a file from the given backend by the file ID

A convenience function to call backend.backend_mod.exists?(backend, file_id)

Get the Exfile.File struct representing a file on the given backend

Opens a file on the given backend, applying postprocessors if configured

A convenience function to call backend.backend_mod.path(backend, file_id)

Puts a value in the “meta” section of the backend setting

A convenience function to call backend.backend_mod.size(backend, file_id)

Uploads a file to the given backend, applying preprocessors if configured

Callbacks

Delete a file from the backend, identified by file_id

Construct an Exfile.File struct representing the given file_id

Open a file from the backend. This function should download the file either to a temporary file or to memory in the Exfile.LocalFile struct

Get the size of a file from the backend

upload/2 must handle at least two cases of uploadable

Link to this section Types

Link to this type backend() View Source
backend() :: t
Link to this type t() View Source
t() :: %Exfile.Backend{backend_mod: atom, backend_name: String.t, directory: String.t, hasher: atom, max_size: integer, meta: map, postprocessors: [Exfile.ProcessorChain.definition, ...], preprocessors: [Exfile.ProcessorChain.definition, ...]}

Link to this section Functions

Link to this function delete(backend, file_id) View Source
delete(backend, file_id) :: :ok | {:error, :file.posix}

Deletes a file from the given backend by the file ID.

Link to this function exists?(backend, file_id) View Source
exists?(backend, file_id) :: boolean

A convenience function to call backend.backend_mod.exists?(backend, file_id)

Get the Exfile.File struct representing a file on the given backend.

This function does not open the file or download it. Use open/2 or Exfile.File.open/1 to open the file.

Link to this function open(backend, file_id) View Source
open(backend, file_id) ::
  {:ok, Exfile.LocalFile.t} |
  {:error, :file.posix}

Opens a file on the given backend, applying postprocessors if configured.

A convenience function to call backend.backend_mod.path(backend, file_id)

Link to this function put_meta(backend, key, value) View Source
put_meta(backend, any, any) :: backend

Puts a value in the “meta” section of the backend setting.

Link to this function size(backend, file_id) View Source
size(backend, file_id) ::
  {:ok, pos_integer} |
  {:error, :file.posix}

A convenience function to call backend.backend_mod.size(backend, file_id)

Link to this function upload(backend, uploadable) View Source
upload(backend, uploadable) ::
  {:ok, Exfile.File.t} |
  {:error, atom}

Uploads a file to the given backend, applying preprocessors if configured.

Link to this section Callbacks

Link to this callback delete(backend, file_id) View Source
delete(backend, file_id) :: :ok | {:error, :file.posix}

Delete a file from the backend, identified by file_id.

Link to this callback exists?(backend, file_id) View Source
exists?(backend, file_id) :: boolean

Construct an Exfile.File struct representing the given file_id.

Link to this callback init(list) View Source
init([{:name, String.t}]) :: backend | {:error, atom}
Link to this callback open(backend, file_id) View Source
open(backend, file_id) ::
  {:ok, Exfile.LocalFile.t} |
  {:error, :file.posix}

Open a file from the backend. This function should download the file either to a temporary file or to memory in the Exfile.LocalFile struct.

Link to this callback size(backend, file_id) View Source
size(backend, file_id) ::
  {:ok, pos_integer} |
  {:error, :file.posix}

Get the size of a file from the backend

Link to this callback upload(backend, uploadable) View Source
upload(backend, uploadable) ::
  {:ok, Exfile.File.t} |
  {:error, atom}

upload/2 must handle at least two cases of uploadable:

  1. an %Exfile.File{}
  2. an %Exfile.LocalFile{}

You may elect to implement a third case that handles uploading between identical backends, if there is a more efficient way to implement it. See Exfile.Backend.FileSystem.upload/2 for an example.