ring-clojure / ring

Clojure HTTP server abstraction
MIT License
3.77k stars 520 forks source link

How to provoke the download window to appear? #325

Closed htmfilho closed 6 years ago

htmfilho commented 6 years ago

Hello,

I'm trying to implement a file download using ring in a way that it forces the browser to open a window to save the file, instead of opening the file in the browser. I've implemented the following function, but it is not behaving as expected:

(defn download-document [id]
  (let [document (document-model/get-it id)]
    (-> (file-response "/path/to/my/document/ugly_file_name.pdf")
         (header "Content-Disposition" "attachment; filename=\"nice_file_name.pdf\"")
         (content-type "application/pdf")
         (header "Content-Length" 3746220))))

The pdf file is still opening in the browser with the ugly file name.

Any hint how to achieve that ? Thank you very much in advance.

weavejester commented 6 years ago

What middleware are you using? What adapter are you using? What does the head of the HTTP response look like?

weavejester commented 6 years ago

Closing due to no response.