I have a handler that returns file to be downloaded by the user. It's something like
(defn- download [req]
(let [data ...
temp-file (File/createTempFile bucket data-file-path)]
(spit temp-file data)
temp-file))
I would like to delete this file as soon as possible without having to resort to some kind of periodical background cleanup process.
Is that possible?If you're running under Linux or some other Unix-like system (like MacOS), then you can open the file as a stream, then immediately delete the original file. Linux will keep files around until all file handles have been closed, so as long as the InputStream exists and is open, the data will remain on disk.
Yes, I am. Thanks for the tip. I will try that