hello, i`m having a hard time making my app redirecting/downloading a .pdf file After saving the pdf on the disk, i return a ring response with the relative path:
(ring.util.response/redirect (str pdf-location "/" pdf-name))
if i inspect in my browser "Networks":
• i see status 302 (the route that handles the logic of downloading the pdf and which returns the redirect response)
• status 200
scheme
http
host
localhost:8080
filename
/35586426/2024/10/3772738448.pdf
I wish the browser redirects to the location : Thanks for the update
Hi, in my application, I use to allow people to download pdfs, zips and so on
bit like this
ok, thank you. I will read about it.
i managed to make it work.
i was using also HTMX in my project, and the http request were made by AJAX
i replaced the htmx's hx-get with an anchor <a>
in my handler:
(defn foo-handler
[request]
...
...
...
(fn [output-stream]
(try
(with-open [in (s3/get-file s3 s3-key)]
(io/copy in output-stream))
(catch Exception e
(log/errorf e "Unable to write to output stream for file '%s'!" s3-key))
in my route
(-> (handler/foo-handler request)
(rio/piped-input-stream)
(response/response)
(response/content-type "application/zip")
(response/header "Content-Disposition" (format "attachment; filename=%s" filename)))))))works a treat
Good luck! 🙂
Thank you so much for your help, good luck as well
Could you explain your issue a little more? You say that you expect it to redirect, but then you also say it returns a 302 then a 200 response - a successful redirection. Is it redirecting to the wrong URL? Is it not downloading the file? You haven't explained what's going wrong.
hello, @weavejester
i did not used it properly.
it was a PEBKAC: Problem Exists Between Keyboard And Chair 😀
i use HTMX in my project, i am using <a> tag which acts like a button and sends hx-get (http get) request. this request is made with ajax.
i resolved my problem by using <a> with href