Add support for setting filename from `content-disposition`
Closed this issue · 3 comments
Environment
- Elixir version (elixir -v): 1.10.0
- Waffle version (mix deps): 1.0.0
- Waffle dependencies when applicable (mix deps):
- Operating system: Linux
Expected behavior
When submitting a URI, content-disposition
should be used to set the filename when available.
Actual behavior
Only the path component is used to set the filename.
I'm willing to implement this and submit a PR, but I can't think of a solution other than sending an initial HEAD request to see if a header is set. Seems like the filename is set higher up in the callstack, and by the time the download actually begins, you're expecting a meaningful filename to be available.
Would such a fix be welcome? I don't feel confident correctly refactoring all the way down the stack (I.e. setting the filename at time of storage. Should the supplementary HEAD
request only be sent if a config flag is set? I can see a case either way--on one hand you're performing additional requests, but on the other, the behavior may be unexpected in some circumstances.
I think it can be handled here: https://github.com/elixir-waffle/waffle/blob/master/lib/waffle/file.ex#L26.
save_file
could return a filename if it was present when downloading the file. We could use it if user didn't pass a custom filename.
Good catch, PR is welcome.