Skip to content

Commit da2052c

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

File tree

1 file changed

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

1 file changed

+20
-0
lines changed

lib/supplement/storages/s3.ex

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,26 @@ 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+
headers = Map.new(headers)
14+
15+
{:ok,
16+
%{
17+
size: Map.fetch!(headers, "Content-Length"),
18+
updated_at: Map.fetch!(headers, "Last-Modified"),
19+
created_at: Map.fetch!(headers, "Date"),
20+
mime_type: Map.fetch!(headers, "Content-Type")
21+
}}
22+
23+
error ->
24+
handle_error(error)
25+
end
26+
end
27+
828
@impl Storage
929
def put(upload, opts \\ []) do
1030
key = opts[:key] || Upload.name(upload)

0 commit comments

Comments
 (0)