2018-08-28 03:20:54 +02:00
|
|
|
defmodule Pleroma.Uploaders.S3 do
|
2018-08-28 14:57:41 +02:00
|
|
|
@behaviour Pleroma.Uploaders.Uploader
|
2018-08-28 03:20:54 +02:00
|
|
|
|
2018-08-28 03:45:53 +02:00
|
|
|
def put_file(name, uuid, path, content_type, _should_dedupe) do
|
2018-08-28 03:20:54 +02:00
|
|
|
settings = Application.get_env(:pleroma, Pleroma.Uploaders.S3)
|
|
|
|
bucket = Keyword.fetch!(settings, :bucket)
|
|
|
|
public_endpoint = Keyword.fetch!(settings, :public_endpoint)
|
|
|
|
|
|
|
|
{:ok, file_data} = File.read(path)
|
|
|
|
|
|
|
|
File.rm!(path)
|
|
|
|
|
|
|
|
s3_name = "#{uuid}/#{name}"
|
|
|
|
|
2018-08-28 03:45:53 +02:00
|
|
|
{:ok, _} =
|
2018-08-28 03:20:54 +02:00
|
|
|
ExAws.S3.put_object(bucket, s3_name, file_data, [
|
|
|
|
{:acl, :public_read},
|
|
|
|
{:content_type, content_type}
|
|
|
|
])
|
|
|
|
|> ExAws.request()
|
|
|
|
|
2018-08-30 03:07:28 +02:00
|
|
|
{:ok, "#{public_endpoint}/#{bucket}/#{s3_name}"}
|
2018-08-28 03:20:54 +02:00
|
|
|
end
|
|
|
|
end
|