Vivek Nayak · Dec 31, 2019

How to save file/image at some specific folder.

Hi Team,

I want to save image/file using inter system iris web api.

I am sending file as Base64 formate  in JSON object to api .and I want to save it at D/Images folder.

please refer below code that i was tried.

Obj.OrganizationLogoBase64--> has base64 value of image

Set decode = $System.Encryption.Base64Decode(Obj.OrganizationLogoBase64)

set file = ##class(%Stream.GlobalBinary).%New()

    do file.Write(decode)

0 391
Discussion (9)2
Log in or sign up to continue

Hi Vivek,

I would suggest using %Stream.FileBinary and then using the LinkToFile method:

Set file=##class(%Stream.FileBinary).%New()
Set sc=file.LinkToFile("c:\myfile.txt")
Do file.Write(decode)

Hi Peter,

Thanks but above solution is not working.

Set Obj.OrganizationLogo="abc.png"

Set path="D:\temp\"_OrganizationLogo
    Set file=##class(%Stream.FileBinary).%New()
    Set sc=file.LinkToFile(path)
    Do file.Write(decode)
just for information
I have created web api in intersystem iris and at front end I am using angular.
So, I am passing this image as base64 formate along with the other fields like fname,lname, address etc..

in JSON 

Have you checked the error codes? Is the file being created?

Set file=##class(%Stream.FileBinary).%New()
Set sc=file.LinkToFile(path)
w $system.Status.GetErrorText(sc)
set sc=file.Write(decode)
w $system.Status.GetErrorText(sc)

File is not created and also not getting any error message

Are you testing this through terminal or your web API? If you are testing through your web API you will need to log the status codes instead of writing them

Also, I am not sure what the rest of the code looks like, but it will also need to be saved:

set sc=file.%Save()

Thanks Peter,

Now it is working fine..

Hi Peter

Can you please help me on how to set status when some error occurs for below statement.


I have tried below code but it is not working

Set status = $$$OK
Set status =$system.Status.GetErrorText(sc)
If ($$$ISERR(status)){
-- Some error handling
else {
-- some success message

You can just check $$$ISERR(sc) directly here, you do not need to run it through $system.Status.GetErrorText(sc)  first.

$$$ISERR(status) will compile into ('status). In the case where sc=1, status will become = "". This means that 'status will evaluate to true when sc=1, which means it will think there is an error when there is not.

USER>set sc=1
USER>set status=$system.Status.GetErrorText(sc)
USER>zw sc
USER>zw status
USER>w ('status)
USER>w ('sc)