Skip to content

Commit 939e6af

Browse files
Send small files using PutObject instead of multipart request
1 parent 2320456 commit 939e6af

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/ex_webrtc_recorder/s3/utils.ex

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@ 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

13-
@chunk_size 5 * 1024 * 1024
14-
1521
@spec upload_manifest(ExWebRTC.Recorder.Manifest.t(), String.t(), String.t(), keyword()) ::
1622
{:ok | :error, term()}
1723
def upload_manifest(manifest, s3_bucket_name, s3_path, s3_config \\ []) do

0 commit comments

Comments
 (0)