Skip to content

Commit cf0c355

Browse files
committed
Implement stat callbacks
1 parent 4bfb7bc commit cf0c355

File tree

1 file changed

+18
-0
lines changed
  • lib/supplement/storages

1 file changed

+18
-0
lines changed

lib/supplement/storages/s3.ex

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ defmodule Capsule.Storages.S3 do
55

66
alias ExAws.S3, as: Client
77

8+
@impl Storage
9+
def stat(id, opts \\ []) do
10+
case Client.head_object(config(opts, :bucket), id)
11+
|> ex_aws_module().request() do
12+
{:ok, %{headers: headers}} ->
13+
{:ok,
14+
%{
15+
size: Keyword.fetch!(headers, "Content-Length"),
16+
updated_at: Keyword.fetch!(headers, "Last-Modified"),
17+
created_at: Keyword.fetch!(headers, "Date"),
18+
mime_type: Keyword.fetch!(headers, "Content-Type")
19+
}}
20+
21+
error ->
22+
handle_error(error)
23+
end
24+
end
25+
826
@impl Storage
927
def put(upload, opts \\ []) do
1028
key = opts[:key] || Upload.name(upload)

0 commit comments

Comments
 (0)