From 1c53d5b2b0798824bca90e431ee2c2dde6e100e8 Mon Sep 17 00:00:00 2001 From: Jim Kane Date: Tue, 5 Nov 2024 12:00:51 -0600 Subject: [PATCH] Refactor stream put --- lib/waffle/storage/s3.ex | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/waffle/storage/s3.ex b/lib/waffle/storage/s3.ex index 3420acc..c84ab9a 100644 --- a/lib/waffle/storage/s3.ex +++ b/lib/waffle/storage/s3.ex @@ -197,24 +197,18 @@ defmodule Waffle.Storage.S3 do when is_struct(file_stream) do file_stream |> chunk_stream() - |> S3.upload(s3_bucket, s3_key, s3_options) - |> ExAws.request() - |> case do - {:ok, %{status_code: 200}} -> {:ok, file.file_name} - {:ok, :done} -> {:ok, file.file_name} - {:error, error} -> {:error, error} - end - rescue - e in ExAws.Error -> - Logger.error(inspect(e)) - Logger.error(e.message) - {:error, :invalid_bucket} + |> do_put_stream(file, {s3_bucket, s3_key, s3_options}) end # Stream the file and upload to AWS as a multi-part upload defp do_put(file, {s3_bucket, s3_key, s3_options}) do file.path |> Upload.stream_file() + |> do_put_stream(file, {s3_bucket, s3_key, s3_options}) + end + + defp do_put_stream(stream, file, {s3_bucket, s3_key, s3_options}) do + stream |> S3.upload(s3_bucket, s3_key, s3_options) |> ExAws.request() |> case do