Skip to content

Instantly share code, notes, and snippets.

@olivermt
Created September 26, 2017 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olivermt/7c7b3b3e71e4571d0e1d81d904daa7ff to your computer and use it in GitHub Desktop.
Save olivermt/7c7b3b3e71e4571d0e1d81d904daa7ff to your computer and use it in GitHub Desktop.
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