I'm sending a file using the response << file.newInputStream (similar to this answer here, but I want to delete this file afterwards. However, when I call delete on this file, it doesn't delete it. I'm quite sure it's because the file is still in use (streaming). How an I check this and then delete.
def tempfile = new File(filename)
if (tempfile) {
response.setContentType("application/octet-stream")
response.setHeader("Content-disposition", "attachment;filename=${tempfile.getName()}")
response.outputStream << tempfile.newInputStream()
} else {
renderErrorMsg("ERROR: Cannot open/find file - ${filename}.")
}
tempfile.delete()
Thanks.