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)
Comments
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"
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.
$system.Status.GetErrorText(sc)
I have tried below code but it is not working
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
sc=1
USER>zw status
status=""
USER>w ('status)
1
USER>w ('sc)
0