Git Product home page Git Product logo

extus's Introduction

Extus

TODO: Add description

Installation

If available in Hex, the package can be installed by adding extus to your list of dependencies in mix.exs:

def deps do
  [{:extus, "~> 0.1.0"}]
end

1. Config

config :extus,
  storage: ExTus.Storage.Local,
  base_dir: "upload",
  expired_after: 24 * 60 * 60 * 1000, #clean uncompleted upload after 1 day
  clean_interval: 30 * 60 * 1000 # start cleaning job after 30min
  • storage: module which handle storage file application Currently, ExTus support ExTus.Storage.Local and ExTus.Storage.S3
  • base_dir is where you want to store uploaded file

Config for S3 uploaded

config :extus,
  storage: ExTus.Storage.S3,
  base_dir: "upload",
	asset_host: "https://dsxymfc8fnnz2.cloudfront.net",

  config :extus, :s3,
    virtual_host: true,
    bucket: "mofiin",
    chunk_size: 5 * 1024 * 1024
  • virtual_host: true if you want to use "https://#{bucket}.s3.amazonaws.com" host. default is "https://s3.amazonaws.com/#{bucket}"
  • asset_host: host which you use to serve uploaded files
  • bucket: name of s3 bucket
  • chunk_size: size of part for multipart upload

2. Dependencies

If you use S3 to store file, add below dependencies

    {:poison, "~> 2.0"},
    {:hackney, "~> 1.6"}

3. Usage

Add new controller for upload

defmodule MyApp.UploadController do
  use MyApp.Web, :controller
  use ExTus.Controller

  # start upload file callback
  def on_begin_upload(file_info) do
    IO.inspect "create file: #{inspect file_info}"
  end
	
  # Completed upload file callback
  def on_complete_upload(file_info) do
    IO.inspect "complete file: #{inspect file_info}"
  end
end

Add route

scope "/files", MyApp do
    options "/",  			TusController, :options
    options "/:file",  		TusController, :options
    match :head, "/:file",  TusController, :head
    post "/",  				TusController, :post
    patch "/:file",  		TusController, :patch
    delete "/:file",  		TusController, :delete
end

4. Implement your own storage

  • In progress You can implement interface Storage

extus's People

Contributors

bluzky avatar skanderm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.