diff --git a/lib/waffle/file.ex b/lib/waffle/file.ex index fb429ef..34c1f5f 100644 --- a/lib/waffle/file.ex +++ b/lib/waffle/file.ex @@ -44,6 +44,13 @@ defmodule Waffle.File do uri = URI.parse(remote_path) case save_file(uri, filename, definition) do + {:ok, local_path, _filename_from_content_disposition} -> + %Waffle.File{ + path: local_path, + file_name: filename, + is_tempfile?: true + } + {:ok, local_path} -> %Waffle.File{path: local_path, file_name: filename, is_tempfile?: true} diff --git a/test/actions/store_test.exs b/test/actions/store_test.exs index 416276d..64f2490 100644 --- a/test/actions/store_test.exs +++ b/test/actions/store_test.exs @@ -245,6 +245,31 @@ defmodule WaffleTest.Actions.Store do end end + test "overrides remote filename from content-disposition header with provided filename" do + with_mocks([ + { + :hackney_headers, + [:passthrough], + get_value: fn "content-disposition", _headers -> + "attachment; filename=\"image three.png\"" + end + }, + { + Waffle.Storage.S3, + [], + put: fn DummyDefinition, _, {%{file_name: "image four.png", path: _}, nil} -> + {:ok, "image four.png"} + end + } + ]) do + assert DummyDefinition.store(%{ + filename: "image four.png", + remote_path: @remote_img_with_space_image_two + }) == + {:ok, "image four.png"} + end + end + test "rejects remote files with filenames and invalid remote path" do with_mock Waffle.Storage.S3, put: fn DummyDefinition, _, {%{file_name: "newfavicon.ico", path: _}, nil} ->