Home

Awesome

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

config :arc,
  storage: Arc.Storage.Ovh.Cloudstorage,
  client: ArcOvh.Client.Cloudstorage,
  container: "default",
  default_tempurl_ttl: (30 * 24 * 60 * 60), # 30 days default time to live for signed urls.
  version_timeout: (60 * 3 * 1000) # 3 minutes
config :arc_ovh, ArcOvh.Client.Cloudstorage,
    adapter: Openstex.Adapters.Ovh,
    ovh: [
      application_key: System.get_env("APPLICATION_KEY"),
      application_secret: System.get_env("APPLICATION_SECRET"),
      consumer_key: System.get_env("CONSUMER_KEY")
    ],
    keystone: [
      tenant_id: System.get_env("TENANT_ID"), # mandatory, corresponds to an ovh project id or ovh servicename
      user_id: System.get_env("USER_ID"), # optional, if absent a user will be created using the ovh api.
      endpoint: "https://auth.cloud.ovh.net/v2.0"
    ],
    swift: [
      account_temp_url_key1: System.get_env("TEMP_URL_KEY1"), # defaults to :nil if absent
      account_temp_url_key2: System.get_env("TEMP_URL_KEY2"), # defaults to :nil if absent
      region: :nil # specify a region if you like. Check your OVH cloud.
    ],
    hackney: [
      timeout: 20000,
      recv_timeout: 40000
    ]

config :httpipe,
  adapter: HTTPipe.Adapters.Hackney

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

<p align="center"> <img src="https://github.com/stephenmoloney/arc_ovh/blob/master/test/fixtures/bundoran.jpg?raw=true" width="600"> </p>

License

MIT Licence