trunk v0.0.5 Trunk.Storage behaviour View Source

This is a behaviour that can be implemented by any storage module to make sure it supports all required functions.

Link to this section Summary

Callbacks

Generates a URL to the S3 object

Deletes the version file from the storage system at path Path.join(directory, filename)

Save the source_file to the storage system on path Path.join(directory, filename)

Link to this section Types

Link to this section Callbacks

Link to this callback build_uri(directory, filename, opts) View Source
build_uri(directory :: String.t, filename :: String.t, opts) :: String.t

Generates a URL to the S3 object

  • directory - The directory
  • filename - The name of the file
  • opts - The options for the storage system, set in Trunk option :storage_opts

Example:

MyStorage.build_url("path/to", "file.ext", some: :opt)
#=> "https://my-storage/my-bucket/path/to/file.ext"
Link to this callback delete(directory, filenae, opts) View Source
delete(directory :: String.t, filenae :: String.t, opts) ::
  :ok |
  {:error, any}

Deletes the version file from the storage system at path Path.join(directory, filename)

  • directory - The directory
  • filename - The name of the file
  • opts - The options for the storage system, set in Trunk option :storage_opts

Example:

The file should be removed from /my-bucket/path/to/file.ext

MyStorage.delete("path/to/", "file.ext", some: :opt)
Link to this callback save(directory, filenae, source_path, opts) View Source
save(directory :: String.t, filenae :: String.t, source_path :: String.t, opts) ::
  :ok |
  {:error, any}

Save the source_file to the storage system on path Path.join(directory, filename)

  • directory - The directory
  • filename - The name of the file
  • source_path - The full path to the file to be stored. This is a path to the uploaded file or a temporary file that has undergone transformation
  • opts - The options for the storage system, set in Trunk option :storage_opts

Example:

The file should be saved to /my-bucket/path/to/file.ext

MyStorage.save("path/to/", "file.ext", "/tmp/uploaded_file.ext", some: :opt)