ArcOvh

Use Arc with the OVH Cloudstorage

Installation

The package can be installed by adding arc_ovh to your list of dependencies in mix.exs:

def deps do
  [{:arc_ovh, "~> 0.2"}]
end

Configuration

Example usage

defmodule DummyDefinitionThumbnail do
    use Arc.Definition
    @versions [:original, :thumbnail]

    def transform(:thumbnail, _) do
      {"convert", "-strip -thumbnail 100x100^ -gravity center -extent 100x100 -format jpg", :jpg}
    end
    # Whitelist file extensions:
    def validate({file, _}) do
      file_extension = file.file_name |> Path.extname() |> String.downcase()
      file_extension in ~w(.jpg .jpeg .gif .png)
    end
    def __storage(), do: Application.get_env(:arc, :storage, Arc.Storage.Ovh.Cloudstorage)

    def storage_dir(_version, {_file, scope}) do
      (scope != :nil && Map.has_key?(scope, :id)) &&
       "#{scope.id}" ||
       ""
    end
    def storage_dir(_version, _) do
       ""
    end

    def filename(version, {file, _scope}) do
      "#{Path.basename(file.file_name) |> Path.rootname()}_#{version}"
    end
end
defp image(), do: Path.join(__DIR__, "./assets/image.jpg") |> Path.expand()

{:ok, object_name} = DummyDefinitionThumbnail.store({image(), %{id: 1}})
original_url = DummyDefinitionThumbnail.url({image(), %{id: 1}}, :original)
thumbnail_url = DummyDefinitionThumbnail.url({image(), %{id: 1}}, :thumbnail)
defp image(), do: Path.join(__DIR__, "./assets/image.jpg") |> Path.expand()

{:ok, object_name} = DummyDefinitionThumbnail.store({image(), %{id: 1}})
original_signed_url = DummyDefinitionThumbnail.url({image(), %{id: 1}}, :original, signed: :true)
thumbnail_signed_url = DummyDefinitionThumbnail.url({image(), %{id: 1}}, :thumbnail, signed: :true)
{:ok, object_name} = DummyDefinitionThumbnail.store({image(), %{id: 1}})
:ok = DummyDefinitionThumbnail.delete({object_name, %{id: 1}})

Tests

License

MIT Licence