Question
· Sep 20, 2021

How to create a file from a stream - save it - change his name and resave it

Hi gentlemen,

It may be very easy but I'm currently battling with a stupid business operation.

Here is what I must do and what is already in place:

A business service scan every 5 sec the apparition of files and send it to a business process.

The business process (a routeur) don't let pass everything and a few of them go to a specific operation.

The operation must :

1 ) create the file with the same name of the original one (in the service) then save it.

2) change the original and resave it a second time (replacing the previous one but without using the function rename)

Hope you can help me.

 

The base of my code must be a stream:

Method OnMessage(pRequest As Ens.StreamContainer, Output pResponse As %Persistent) As %Status
{
}

Thanks

Discussion (2)1
Log in or sign up to continue

Hi Thomas,

You can write to a file by using the %File library class as follows:

        set tTempFile=##class(%FileCharacterStream).%New()
        set tTempFile.Filename=filename
        set tSC=tTempFile.CopyFrom(tStream)
        set returnValue=tTempFile.%Save()
 

You will be able to get the file name that was read in the service from the Ens.StreamContainer. It has a property called OriginalFilename that has the absolute filename saved. If the business service managed to pick up the type of file that it processed it will be populated in the Type property.