%Stream files do not get purged from the <namespace>/stream/ folder on the system disk
As the title says, I've noticed that files that gets saved to the disk where the database lies (.DAT file) in the stream directory, does not get purged. Is this expected and do we need to create our own schedule task to clean this folder up?
I could only find old answers that say this, however I find it a bit odd if that is the case because they are considered temporary files. Perhaps I do not handle the streams correctly in the code?
set fileToDisk = ##class(%Stream.FileBinary).%New()
set fileToDisk.Filename = fileDestinationPath
set copyStatus = fileToDisk.CopyFromAndSave(response.Data)Comments
%Stream.FileBinary objects are not considered temporary files. You probably want to be using %Stream.TmpBinary objects.
That's probably it - thank you, but what is the point of permanently storing the stream on disk when the %Stream.FileBinary object is no longer in use since the code has finished executing.
You explicitly saved the stream using CopyFromAndSave(), so it will persist (on disk) until it's deleted.
It's like saving a persistent class, it persist even when the code has finished executing. Fortunately! ☺
What's the point of saving a stream that you don't want to persist?
https://docs.intersystems.com/irisforhealthlatest/csp/documatic/%25CSP…
Am I missing something? I am saving the data inside response.Data to the fileDestinationPath, which works but it also saves to the database stream folder and never gets purged.
I understand I have to use TmpBinary instead but what is the point of keeping a copy in the stream folder when the code has finished executing? the files are also not named in a way that makes them recognizable other than their extension and file size.
Basically the file is saved to both the location I set at fileDestinationPath and the stream folder where the database file resides.
This is new info, you did not mention this in your original question.
Can you provide some context on your implementation?
Would you mind to share the code you are using to save "data inside response.Data"?
What class is "response"?
Here's an update, I went back to what I used initially %Stream.FileBinary, and setting RemoveOnClose to true fixed my issue with the file being saved in the stream folder where the database files are with a randomly generated name
https://docs.intersystems.com/irisforhealth20251/csp/documatic/%25CSP.D…
So I've created a custom message structure for stuffing PDFs extracted from HL7 messages into a COLD feed. I've been using %Stream.FileBinary as the object type for the stream property in the class. I hadn't given much thought to the fact that those streams might hang around after a message purge, so I went back and modified the class to use %Stream.TmpBinary. I mean, that seems to make sense, right?
Except that with %Stream.TmpBinary, the stream goes away as soon as the message leaves the business process, and no file gets written by the operation. Oops.
So I'm back to using %Stream.FileBinary ... I would hope that the Interoperability message purge task would "do the right thing" and delete the stream since the message object extends Ens.Request, but I suppose I should do some experimentin' 😉
From the example in the first post it seems the stream is not a property of an Ens.Message, that's why is not purged.