Skip to Content

Delete a file after it's being served

Seen on #clojure:

nonuby : any thoughts for best approach to delete a file after its being served by ring since returning { :body (FileInputStream. "/tmp/123324.pdf") }. Im thinking of decorator approach where .close then delete the files after passing .close to the inner inputstream

justin_smith : nonuby: what if you never put it on disk in the first place, and just handed an input stream that would be garbage collected to the client?

justin_smith : nonuby: either generate it directly into the stream, or if that can't be done, put the contents in an input stream, delete, then return the stream