Skip to content

Commit

Permalink
fix: handle upload fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ali1ariel committed Dec 8, 2024
1 parent 67a6000 commit 3f8a538
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
7 changes: 6 additions & 1 deletion lib/digistab_store_web/helpers/error_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ defmodule DigistabStoreWeb.ErrorHelpers do
)

def error_to_string(:external_client_failure),
do: Gettext.dgettext(DigistabStoreWeb.Gettext, "errors", "Failed to upload")
do:
Gettext.dgettext(
DigistabStoreWeb.Gettext,
"errors",
"Failed to upload - external_client_failure"
)

def error_to_string(_) do
Gettext.dgettext(DigistabStoreWeb.Gettext, "errors", "Failed to upload")
Expand Down
43 changes: 25 additions & 18 deletions lib/digistab_store_web/live/products/form_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ defmodule DigistabStoreWeb.ProductLive.FormComponent do
for entry <- completed do
key = "digistab_store/products/#{entry.client_name}"

dest = Path.join("http://#{s3_config().bucket}.s3.amazonaws.com", key)
dest = Path.join("https://#{s3_config().bucket}.s3.amazonaws.com", key)

%{"url" => dest}
end
Expand Down Expand Up @@ -609,24 +609,31 @@ defmodule DigistabStoreWeb.ProductLive.FormComponent do
# AWS fields for secure file uploads, as well as any necessary file restrictions.
defp presign_upload(entry, socket) do
uploads = socket.assigns.uploads
key = "digistab_store/products/#{entry.client_name}"

{:ok, fields} =
SimpleS3Upload.sign_form_upload(s3_config(), s3_config().bucket,
key: key,
content_type: entry.client_type,
max_file_size: uploads[entry.upload_config].max_file_size,
expires_in: :timer.hours(1)
)

meta = %{
uploader: "S3",
key: key,
url: "http://#{s3_config().bucket}.s3-#{s3_config().region}.amazonaws.com",
fields: fields
}

{:ok, meta, socket}
case uploads[entry.upload_config] do
nil ->
{:error, :upload_cancelled}

upload_config ->
key = "digistab_store/products/#{entry.client_name}"

{:ok, fields} =
SimpleS3Upload.sign_form_upload(s3_config(), s3_config().bucket,
key: key,
content_type: entry.client_type,
max_file_size: upload_config.max_file_size,
expires_in: :timer.hours(1)
)

meta = %{
uploader: "S3",
key: key,
url: "https://#{s3_config().bucket}.s3-#{s3_config().region}.amazonaws.com",
fields: fields
}

{:ok, meta, socket}
end
end

# s3 config params at runtime execution
Expand Down

0 comments on commit 3f8a538

Please sign in to comment.