FileStorageApi.File behaviour (file_storage_api v2.1.2)

Module for uploading deleting and fetching url of file

Summary

Functions

public_url returns an full url to be able to fetch the file with security tokens needed by default 1 day valid

Function to upload file has input args container_name: name of the container filename: path to the file with the data to store blob_name: how the blob is going to be called after storage

This function will create a temporary file and upload to asset store

Types

@type t() :: %FileStorageApi.File{name: String.t(), properties: map()}

Callbacks

Link to this callback

delete(t, t, arg3)

@callback delete(String.t(), String.t(), atom() | map()) :: {:ok, map()} | {:error, map()}
Link to this callback

last_modified(t)

@callback last_modified(t()) :: {:ok, DateTime.t()} | {:error, atom()}
Link to this callback

public_url(t, t, keyword)

@callback public_url(String.t(), String.t(), keyword()) ::
  {:ok, String.t()} | {:error, String.t()}
Link to this callback

upload(t, arg2, t, t, t)

@callback upload(String.t(), atom() | map(), String.t(), String.t(), Keyword.t()) ::
  {:ok, String.t()} | {:file_upload_error, map() | tuple()}

Functions

Link to this function

delete(container_name, filename, connection \\ :default)

@spec delete(String.t(), String.t(), atom()) :: {:ok, map()} | {:error, map()}

Function to delete files

Has 2 inputs container_name: name of container file is stored in filename: reference path of the file stored in the container

Link to this function

last_modified(file, connection \\ :default)

Link to this function

public_url(container_name, file_path, opts)

@spec public_url(String.t(), String.t(), keyword()) ::
  {:ok, String.t()} | {:error, String.t()}

public_url returns an full url to be able to fetch the file with security tokens needed by default 1 day valid

@spec sanitize(binary()) :: binary()
Link to this function

upload(container_name, filename, blob_name, opts \\ [])

@spec upload(String.t(), String.t(), String.t(), keyword()) ::
  {:ok, String.t()}
  | {:file_upload_error, map() | tuple()}
  | {:error, :invalid_file}

Function to upload file has input args container_name: name of the container filename: path to the file with the data to store blob_name: how the blob is going to be called after storage

Option field is available that has options for missing container fallback force_container: with false you can disable auto creation of container public: with public on true it will create bucket by default as public cors_policy: can have true or a configuration for configuring cors settings of bucket

Returns reference to the file in the asset store

Link to this function

upload_file_from_content(filename, container_name, content, blob_name, opts \\ [])

@spec upload_file_from_content(
  binary(),
  binary(),
  binary() | iodata(),
  binary(),
  keyword()
) ::
  {:ok, String.t()} | {:file_upload_error, map() | tuple()}

This function will create a temporary file and upload to asset store

Opts field described at the upload function