Skip to content

Commit 1c53d5b

Browse files
committed
Refactor stream put
1 parent 3bd1c57 commit 1c53d5b

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

lib/waffle/storage/s3.ex

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -197,24 +197,18 @@ defmodule Waffle.Storage.S3 do
197197
when is_struct(file_stream) do
198198
file_stream
199199
|> chunk_stream()
200-
|> S3.upload(s3_bucket, s3_key, s3_options)
201-
|> ExAws.request()
202-
|> case do
203-
{:ok, %{status_code: 200}} -> {:ok, file.file_name}
204-
{:ok, :done} -> {:ok, file.file_name}
205-
{:error, error} -> {:error, error}
206-
end
207-
rescue
208-
e in ExAws.Error ->
209-
Logger.error(inspect(e))
210-
Logger.error(e.message)
211-
{:error, :invalid_bucket}
200+
|> do_put_stream(file, {s3_bucket, s3_key, s3_options})
212201
end
213202

214203
# Stream the file and upload to AWS as a multi-part upload
215204
defp do_put(file, {s3_bucket, s3_key, s3_options}) do
216205
file.path
217206
|> Upload.stream_file()
207+
|> do_put_stream(file, {s3_bucket, s3_key, s3_options})
208+
end
209+
210+
defp do_put_stream(stream, file, {s3_bucket, s3_key, s3_options}) do
211+
stream
218212
|> S3.upload(s3_bucket, s3_key, s3_options)
219213
|> ExAws.request()
220214
|> case do

0 commit comments

Comments
 (0)