Skip to content

thiagomajesk/dropkick

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dropkick

Dropkick is a highly experimental library that provides easy to use uploads for the Elixir/ Phoenix ecosystem.
This is a opinionated library focused on developer ergonomics that you can use to provide file uploads in any Phoenix project.

Installation

def deps do
  [
    {:dropkick, ">= 0.0.0"}
  ]
end

Usage

Setup

  • Add a map column to your database table: add(:avatar, :map)
  • Add a Dropkick.File field to your ecto schema: field(:avatar, Dropkick.File)

Configuration

Add the following configuration to your config.exs:

config :dropkick,
  repo: MyAppRepo,
  storage: Dropkick.Storage.Disk,
  folder: "uploads"

Uploader

Define an uplodader for your application:

defmodule MyApp.Uploader do
  use Dropkick.Uploader

  # Defines where to store the user avatar through pattern matching
  def storage_prefix({user, :avatar}), do: "avatars/#{user.id}"

  # You can also implement a list of callbacks that allow you to 
  # customize what happens in your upload pipeline
  # def process(file, _scope), do: {:ok, file}
  # def before_store(file, _scope), do: {:ok, file}
  # def after_store(file, _scope), do: {:ok, file}
  # def before_delete(file, _scope), do: {:ok, file}
  # def after_delete(file, _scope), do: {:ok, file}
end 

Save the files

import Dropkick.Context

def create_user(user, attrs) do
  user
  |> User.changeset(attrs)
  |> insert_with_files(MyApp.Uploader)
end

def update_user(user, attrs) do
  user
  |> User.changeset(attrs)
  |> update_with_files(MyApp.Uploader)
end

Missing bits

  • Add integration for file transformations
  • Add integration with Briefly to make transformation/ cleanup of temporary files easier.
  • Support other types of storages (S3, Azure, etc)
  • Add strategy to allow cleaning up old files after update
  • Improve documentation and examples for modules and functions
  • Add examples of using libraries for processing files: