From 939e6afa358dac9285693865c8b5a698d9567f7f Mon Sep 17 00:00:00 2001 From: Tomasz Mazur <47872060+AHGIJMKLKKZNPJKQR@users.noreply.github.com> Date: Wed, 24 Sep 2025 15:14:39 +0200 Subject: [PATCH] Send small files using PutObject instead of multipart request --- lib/ex_webrtc_recorder/s3/utils.ex | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/ex_webrtc_recorder/s3/utils.ex b/lib/ex_webrtc_recorder/s3/utils.ex index 23219b7..191a2be 100644 --- a/lib/ex_webrtc_recorder/s3/utils.ex +++ b/lib/ex_webrtc_recorder/s3/utils.ex @@ -2,16 +2,22 @@ if Code.ensure_loaded?(ExAws.S3) do defmodule ExWebRTC.Recorder.S3.Utils do @moduledoc false + @chunk_size 5 * 1024 * 1024 + @spec upload_file(Path.t(), String.t(), String.t(), keyword()) :: {:ok | :error, term()} def upload_file(path, s3_bucket_name, s3_path, s3_config \\ []) do - path - |> ExAws.S3.Upload.stream_file() - |> ExAws.S3.upload(s3_bucket_name, s3_path) + case File.stat!(path) do + %File.Stat{size: size} when size != :undefined and size <= @chunk_size -> + ExAws.S3.put_object(s3_bucket_name, s3_path, File.read!(path)) + + _else -> + path + |> ExAws.S3.Upload.stream_file() + |> ExAws.S3.upload(s3_bucket_name, s3_path) + end |> ExAws.request(s3_config) end - @chunk_size 5 * 1024 * 1024 - @spec upload_manifest(ExWebRTC.Recorder.Manifest.t(), String.t(), String.t(), keyword()) :: {:ok | :error, term()} def upload_manifest(manifest, s3_bucket_name, s3_path, s3_config \\ []) do