Created
September 26, 2017 08:19
-
-
Save olivermt/7c7b3b3e71e4571d0e1d81d904daa7ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defp do_send_file(conn, file, opts \\ []) do | |
path = Path.join(filestorage_path(), file.file_path_hash) | |
Logger.debug "Streaming file #{path}" | |
if File.exists?(path) do | |
conn = case Keyword.has_key?(opts, :attachment) do | |
true -> put_resp_header(conn, "content-disposition", "attachment; filename=\"#{file.original_file_name}\"") | |
false -> put_resp_header(conn, "content-disposition", "filename=\"#{file.original_file_name}\"") | |
end | |
put_resp_header(conn, "content-type", file.content_type) | |
|> send_file(200, path) | |
else | |
conn | |
|> send_resp(:not_found, "") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment