Skip to content

Instantly share code, notes, and snippets.

@karlosmid
Created May 17, 2020 12:34
Show Gist options
  • Save karlosmid/9446523d4ee5576be8ba640cca041f6d to your computer and use it in GitHub Desktop.
Save karlosmid/9446523d4ee5576be8ba640cca041f6d to your computer and use it in GitHub Desktop.
defmodule Testivator.File do
@moduledoc """
Arc.Ecto definition for charter data files upload
"""
use Arc.Definition
use Arc.Ecto.Definition
# Include ecto support (requires package arc_ecto installed):
# use Arc.Ecto.Definition
@versions [:original]
# To add a thumbnail version:
# @versions [:original, :thumb]
# Whitelist file extensions:
def validate({file, _}) do
Enum.member?(~w(.txt .pdf .doc .odt), Path.extname(file.file_name))
end
# Define a thumbnail transformation:
# def transform(:thumb, _) do
# {:convert, "-strip -thumbnail 250x250^ -gravity center -extent 250x250 -format png", :png}
# end
def bucket, do: :"testivator-files"
# Override the persisted filenames:
# def filename(version, _) do
# version
# end
# Override the storage directory:
# def storage_dir(version, {file, scope}) do
# "uploads/user/avatars/#{scope.id}"
# end
# Provide a default URL if there hasn't been a file uploaded
# def default_url(version, scope) do
# "/images/avatars/default_#{version}.png"
# end
# Specify custom headers for s3 objects
# Available options are [:cache_control, :content_disposition,
# :content_encoding, :content_length, :content_type,
# :expect, :expires, :storage_class, :website_redirect_location]
#
# def s3_object_headers(version, {file, scope}) do
# [content_type: Plug.MIME.path(file.file_name)]
# end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment