elixir-waffle/waffle_ecto

Don't require `%{filename: _, path: _}` maps to be `Plug.Upload` structs

Closed this issue · 2 comments

Waffle does not have any matching on Plug.Upload structs, it just matches on %{filename: _, path: _}.

With Waffle.Ecto, there is currently no way to supply a plain map like that, because it explicitly matches on Plug.Upload here.

It would be nice if maps in that format were also accepted. My use case is having a local file that I want to upload, but with a different filename.

I would be happy to open a PR for this.

For a bit more context, this is what I need to do currently:

    updated_file =
      case file do
        %{filename: _, binary: _} = file_hash ->
          %{file_hash | filename: document_params.key}

        %{filename: _, path: _} = file_hash ->
          %Plug.Upload{file_hash | filename: document_params.key}

        path when is_binary(path) ->
          %Plug.Upload{filename: document_params.key, path: path}
      end

There is also a similar case when casting urls, it would also be great to be able to override the filename in such case.

I would keep the plug as is and add new section to support custom filenames for paths and urls.

PR is welcome 👍