stein_storage v0.1.0 Stein.Storage behaviour View Source
Stein.Storage
covers uploading, downloading, and deleting remote files
Available backends
FileBackend
The Stein.Storage.FileBackend
is available for development purposes.
For the file backend, you can configure the folder Stein should use. This should be a local folder that Elixir has read/write permissions to. It should end with a trailing slash.
config :stein_storage,
backend: :file,
file_backend_folder: "uploads/"
The default folder is Stein's priv/files
.
To fully support the file storage, you should also add a new Plug.Static
to your endpoint. This will let the URLs the backend returns load.
if Mix.env() == :dev do
plug(Plug.Static, at: "/uploads", from: "uploads/files")
end
S3Backend
The Stein.Storage.S3Backend
handles uploading, downloading, and deletes
from Amazon S3.
For the S3 backend, you can also configure the bucket Stein should upload to.
config :stein_storage,
backend: :s3,
bucket: "my-bucket"
MockBackend
The Stein.Storage.MockBackend
mocks out all actions for use in tests. Each
action is a no-op.
config :stein_storage,
backend: :test
Link to this section Summary
Types
A processed file ready for uploading
Key for where the document will be stored
A local file path
Options for a function
The URL for viewing the remote file
Functions
Delete files from remote storage
Download files from remote storage
Prepare a file for upload to the backend
Upload files to the remote storage
Get the remote url for viewing an uploaded file
Callbacks
Delete files from remote storage
Download files from remote storage
Upload files to the remote storage
Get the remote url for viewing an uploaded file
Link to this section Types
A processed file ready for uploading
Key for where the document will be stored
Must start with a leading /
A local file path
Options for a function
The URL for viewing the remote file
Link to this section Functions
Delete files from remote storage
Download files from remote storage
Note: this creates a temporary file and must be cleaned up manually
Prepare a file for upload to the backend
Must be a Stein.Storage.FileUpload
, Plug.Upload
, or a map that
has the :path
key.
Upload files to the remote storage
Limiting extensions
You can limit extensions with the extensions
option. Only the extensions in the list
will be allowed, any other extension will be rejected with {:error, :invalid_extension}
.
Each extension should start with a .
.
Stien.Storage.upload(file, key, extensions: [".jpg", ".png"])
Get the remote url for viewing an uploaded file
Link to this section Callbacks
Delete files from remote storage
Download files from remote storage
Note: this creates a temporary file and must be cleaned up manually
Upload files to the remote storage
Get the remote url for viewing an uploaded file