Skip to content

Commit 2e164e8

Browse files
Send small files using PutObject instead of multipart request (#6)
1 parent 8b2fc97 commit 2e164e8

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/ex_webrtc_recorder/s3/utils.ex

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@ if Code.ensure_loaded?(ExAws.S3) do
22
defmodule ExWebRTC.Recorder.S3.Utils do
33
@moduledoc false
44

5+
@chunk_size 5 * 1024 * 1024
6+
57
@spec upload_file(Path.t(), String.t(), String.t(), keyword()) :: {:ok | :error, term()}
68
def upload_file(path, s3_bucket_name, s3_path, s3_config \\ []) do
7-
path
8-
|> ExAws.S3.Upload.stream_file()
9-
|> ExAws.S3.upload(s3_bucket_name, s3_path)
9+
case File.stat!(path) do
10+
%File.Stat{size: size} when size != :undefined and size <= @chunk_size ->
11+
ExAws.S3.put_object(s3_bucket_name, s3_path, File.read!(path))
12+
13+
_else ->
14+
path
15+
|> ExAws.S3.Upload.stream_file()
16+
|> ExAws.S3.upload(s3_bucket_name, s3_path)
17+
end
1018
|> ExAws.request(s3_config)
1119
end
1220

0 commit comments

Comments
 (0)