Decode base64 file

209 views
Skip to first unread message

Alberto Márquez

unread,
Mar 30, 2009, 7:30:50 AM3/30/09
to InterSystems: Ensemble in Healthcare
Hello,

I have a %xsd.base64Binary property from a soap message. It contains
a binary base64 coded file. How I can decode and save the file in a
physical location within the filesystem?

I tried using the XSDToLogical method for decode the file, but It
don't know how to write the %Binary object returned to a file.

Thank you in advance.

Regards.

sween

unread,
Mar 30, 2009, 8:17:52 AM3/30/09
to InterSystems: Ensemble in Healthcare
this is probably half an answer for you, but here it goes.

You could decode using the $system.Encryption class...

Set vOut=($system.Encryption.Base64Decode(result.Value))

build the result into a stream, such as a %Stream.GlobalCharacter and
go from there...

Alberto Márquez

unread,
Mar 30, 2009, 10:15:41 AM3/30/09
to InterSystems: Ensemble in Healthcare

Ok, I will try it.

Thank you so much.
> > Regards.- Hide quoted text -
>
> - Show quoted text -

Scott Roth

unread,
Mar 28, 2016, 10:01:29 AM3/28/16
to InterSystems: Ensemble in Healthcare
Were you able to get this to work? How did you do this? We are looking into replicating this to Decode Base64 on a HL7 message and store the pdf.

Thanks

Scott Roth
Sr Applications Development Analyst

The Ohio State University Wexner Medical Center

Scott...@osumc.edu


Graham, Ben

unread,
Mar 28, 2016, 12:14:18 PM3/28/16
to Ensemble-in...@googlegroups.com

Here is a COS routine used to validate PDF files embedded in HL7…

 

           
            "Not implemented",!
            Q
Check  //Here is where it starts
            Read "Message Id: ",mid
            !
            q:mid=""
           
            message=##class(EnsLib.HL7.Message).%OpenId(mid)
            Q:'$ISOBJECt(message)
           
            "Field: //ORCgrp(1).OBRgrp(2).OBXgrp(1).OBX:5(1).5? ",field
            s:field="" field="ORCgrp(1).OBRgrp(2).OBXgrp(1).OBX:5(1).5"
           
            pdfStream=##class(%Stream.TmpBinary).%New()
            file=##class(%FileBinaryStream).%New()
            remainder=""
           
            //s tSC=message.GetFieldStreamBase64(pdfStream,field,remainder,0)
            set tSC=message.GetMutableSegmentAt("ORCgrp(1).OBRgrp(2).OBXgrp(1).OBX").GetFieldStreamRaw(pdfStream,"5.5")
           
            "Size of file: ",pdfStream.Size,!
            Q:pdfStream.Size=0
            "Remainder: ",remainder,!
           
            Q:'$ISOBJECT(pdfStream)
            pdfStream.Rewind()
           
            "File will be written to the h:\Temp\PDF_Validate folder on the Ensemble server",!
            Read "FileName: ",filename
            if filename="" !,"no filename given... not writing file...",! Q
            !
           
            set file.Filename="h:\Temp\PDF_Validate\"_filename
            set tSC=file.Rewind()
             
            pdfStream.Rewind()

            While 'pdfStream.AtEnd {
                        //set tSC = file.Write(pdfStream.ReadLine())
                        set tSC = file.Write($system.Encryption.Base64Decode(pdfStream.ReadLine()))
                       
            }
           
           
            tSC = file.%Save()
             
           
           
            file = ""
           

--
You received this message because you are subscribed to the Google Groups "InterSystems: Ensemble in Healthcare Community" group.
To post to this group, send email to Ensemble-in...@googlegroups.com
To unsubscribe from this group, send email to Ensemble-in-Healt...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/Ensemble-in-Healthcare?hl=en
---
You received this message because you are subscribed to the Google Groups "InterSystems: Ensemble in Healthcare" group.
To unsubscribe from this group and stop receiving emails from it, send an email to Ensemble-in-Healt...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.






This electronic transmission and any documents accompanying this electronic transmission may contain information that is confidential and/or legally privileged. The information is intended only for the use of the individual or entity named above. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or the taking of any action in reliance on or regarding the contents of this electronically transmitted information is strictly prohibited. If you have received this e-mail in error, please notify the sender and delete this message immediately.

Scott Roth

unread,
Apr 18, 2016, 3:17:33 PM4/18/16
to InterSystems: Ensemble in Healthcare
I was able to create the following...

ClassMethod DecodeBase64HL7(base64 As %Stream, Path As %String, FileName As %String) As %Boolean
{
// Decode
set Oref = ##class(%File).%New(Path_FileName)
Do Oref.Close()
Do Oref.Open("WSN",10)
Do base64.Rewind()
IF 'Oref.IsOpen Quit "0 - File not open"

While 'base64.AtEnd {
    set ln=base64.ReadLine()
    set lnDecoded=$system.Encryption.Base64Decode(ln)
do Oref.Write(lnDecoded)
}

Do Oref.%Close()
Quit 1
}

But when I use this method I am getting "Cannot extract the embedded font 'FAAAEF + Arial Narrow - Bold'. Some characters may not display correctly.

Has anyone run into this issue in DecodingBase64?

Thanks
Scott Roth
Sr Application Development Analyst

Lawrence Harris

unread,
Apr 18, 2016, 3:26:48 PM4/18/16
to InterSystems: Ensemble in Healthcare
As a first try I would change %File to %FileBinaryStream to ensure there is no extra line breaks etc. being added.

Lawrence

Scott Roth

unread,
Apr 18, 2016, 3:46:34 PM4/18/16
to InterSystems: Ensemble in Healthcare
Disregaurd my last message the issue was with using %File vs using %FileBinaryStream.

ClassMethod DecodeBase64HL7(base64 As %Stream, Path As %String, FileName As %String) As %Boolean
{
// Decode
set Oref = ##class(%FileBinaryStream).%New()
set Oref.Filename = Path_FileName
Do base64.Rewind()


While 'base64.AtEnd {
    set ln=base64.ReadLine()
    set lnDecoded=$system.Encryption.Base64Decode(ln)
do Oref.Write(lnDecoded)
}

Do Oref.%Save()
Quit 1
}

Dale du Preez

unread,
Apr 20, 2016, 2:17:34 PM4/20/16
to Ensemble-in...@googlegroups.com
Hi Scott,

Where are you seeing this error in the UI? If you are decoding HTML and then displaying that content in a browser, it's possible that the content is not being escaped correctly, so this could trigger problems like this.

Dale

Scott Roth

unread,
Apr 21, 2016, 8:57:45 AM4/21/16
to InterSystems: Ensemble in Healthcare
I was seeing the error when I would open the PDF in adobe. The issue was using %File and not %FileBinaryStream.

Scott
Reply all
Reply to author
Forward
0 new messages