ea9e49cbf45fee7e1466f19278ffaeefe1b6f28e
[akkoma] / lib / pleroma / uploaders / s3.ex
1 defmodule Pleroma.Uploaders.S3 do
2
3 def put_file(name, uuid, path, content_type, _should_dedupe) do
4
5 settings = Application.get_env(:pleroma, Pleroma.Uploaders.S3)
6 bucket = Keyword.fetch!(settings, :bucket)
7 public_endpoint = Keyword.fetch!(settings, :public_endpoint)
8
9 {:ok, file_data} = File.read(path)
10
11 File.rm!(path)
12
13 s3_name = "#{uuid}/#{name}"
14
15 {:ok, _} =
16 ExAws.S3.put_object(bucket, s3_name, file_data, [
17 {:acl, :public_read},
18 {:content_type, content_type}
19 ])
20 |> ExAws.request()
21
22 "#{public_endpoint}/#{bucket}/#{s3_name}"
23 end
24 end