Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/waffle/file.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
25 changes: 25 additions & 0 deletions test/actions/store_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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} ->
Expand Down