Honu
https://en.wikipedia.org/wiki/Green_sea_turtle#Taxonomy
A WIP file upload and attachment library for Ecto
Installation
The package can be installed by adding honu to your list of dependencies in mix.exs:
def deps do
[
{:honu, "~> 0.3.2"}
]
endUsage
After installation it's necessary to create a folder in where the files will reside for the default Storage behaviour.
mkdir storage
touch storage/.keep
echo '# Honu storage\n/storage/*\n!/storage/.keep' >> .gitignoreAfter, generate the migration file for the blobs table:
mix ecto.gen.migration create_honu_blobsAnd change the file to the following:
defmodule MyApp.Repo.Migrations.CreateHonuBlobs do
use Ecto.Migration
require Honu.Migration
def change do
Honu.Migration.create_blobs_table()
end
endConfigure the environments accordingly:
# dev.exs
config :honu, Honu.Storage,
storage: Honu.Storage.Disk,
repo: MyApp.Repo,
root_dir: "storage"Optional, Honu also was support to serve the attachments. To do so, add the following configuration to the necessary environments:
config :honu, HonuWeb.Storage,
storage: HonuWeb.Storage.Disk,
# You can use mix phx.gen.secret to generate the secret
secret_key_base: "SECRET HERE",
repo: MyApp.Repo,
service_urls_expire_in: 300And finally forward the requests to the Honu app. In phoenix it's possible to do it with the following:
# router.ex
scope "/honu" do
pipe_through :browser
forward "/", HonuWeb.Router
endSince HonuWeb.Router is just a plug app, it's also possible to add it to other plug apps besides phoenix. If it's done so, it's important to add CSRF protection for the delete endpoint.