Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bettyblocks/file_storage_api
https://github.com/bettyblocks/file_storage_api
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/bettyblocks/file_storage_api
- Owner: bettyblocks
- Created: 2021-07-12T14:16:02.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-02-27T15:48:11.000Z (10 months ago)
- Last Synced: 2024-03-28T18:09:05.526Z (9 months ago)
- Language: Elixir
- Size: 97.7 KB
- Stars: 1
- Watchers: 6
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
![elixir workflow](https://github.com/bettyblocks/file_storage_api/actions/workflows/elixir.yml/badge.svg)
[![Hex.pm](https://img.shields.io/hexpm/v/file_storage_api.svg)]()
[![Hex Docs](https://img.shields.io/badge/hex-docs-blue.svg)](https://hexdocs.pm/file_storage_api)# FileStorageApi
Library to be able to upload and manage files to different storage service azure/s3
## Installation
It can be added to your project by adding
```elixir
def deps do
[
{:file_storage_api, "~> 1.0"}
]
end
```Configuration
Ability to set storage engine currently `S3` and `Azure` supported.
For tests `Mock` can be used with the mox library.
```elixir
config :file_storage_api, :storage_api, engine: Azure
```S3 configuration (options from ex_aws_s3 library)
```elixir
config :file_storage_api, :s3_config,
host: "127.0.0.1",
scheme: "http://",
port: 9000,
access_key_id: "admin",
secret_access_key: "password",
path_style: true
```For test S3 can also be mocked by
```elixir
config :file_storage_api, :s3_config, module: AwsMock
```Azure configuration (options from azure library)
```elixir
config :file_storage_api, :azure_blob,
account_key: "password",
account_name: "user",
environment_suffix: "core.windows.net",
host: ,
development: "true" || "false"
```It will need the package `file` in linux to be able to read mime types and work.
## Dynamic configuration
You can use a map or keyword list to pass a long dynamic configuration in the connection field.
For azure
```elixir
%{
engine: :azure,
config: %{
host: "postfix.example",
secret_key: "YWNjb3VudF9rZXk=",
access_key: "amazing"
}
}
```For S3
```elixir
%{
engine: :s3,
config: %{host: "test.example", secret_key: "test123", access_key: "amazing", scheme: "http://"}
}
```For mocking you can set the engine to Mock
## Multiple storage accounts
It can be necessary to connect to multiple S3- or Azure-accounts. This can be done by adding multiple connections, each with its own engine. To facilitate testing, it is possible to change the engine per connection.
> :warning: A connection-name **must** end with `_conn`.---
#### Example
Make a custom-connection, with a S3-engine in development, and a Azure-engine in production.
File: `config/dev.exs`:
```elixir
config :file_storage_api, :custom_conn, engine: :s3config :file_storage_api, :custom_s3_config,
host: "127.0.0.1",
scheme: "http://",
port: 9000,
access_key_id: "custom-admin",
secret_access_key: "custom-password",
path_style: true
```File: `config/prod.exs`:
```elixir
config :file_storage_api, :custom_conn, engine: :azureconfig :file_storage_api, :custom_azure_blob,
account_key: "custom-password",
account_name: "custom-user",
environment_suffix: "core.windows.net",
host: ,
development: "true" || "false"
```