[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Base64 Decoding/Raw vs. Post



I use http_url_post_xml() to receive a pdf file that is Base64 encoded.  Below is my incoming() procedure.  In the tag PDFData is the Base64 encoded data and I decode and write it out to an IFS file when I receive the tag HOSLog3.  Let me know if you have questions on anything I am doing here.

     P Incoming        B
     D Incoming        PI
     D   LoadId                      10i 0
     D   depth                       10I 0 value
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   value                    65535A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)

     d Program         c                   'UTILS/XUSERMSG'

     D attrname        s           1024A   varying
     D attrval         s          65535A   varying
     d BigMsg          s            512
     D count           s             10I 0
     d Filename        s            100    varying
     d Msg             s             50
     d retlen          s             10i 0
     d TimeString      s             26
     d User            s             10

     D atoi            PR            10i 0 extproc('atoi')
     D   string                        *   value options(*string)


      /free
         //Msg = 'In:' + name;
         //dsply Msg 'SCOTT';
         //Msg = 'Value:' + value;
         //dsply Msg 'SCOTT';
         select;
           when name = 'HOSLog3';
             count = 1;
             dow http_nextXmlAttr(attrs: count: attrname: attrval);
               select;
                 when (attrname = 'id');
                   //Msg = 'ID=' + attrval;
                   //dsply Msg 'SCOTT';
                   LastIndex = %int(%trim(attrval));
                 when (attrname = 'date');
                   LogDate = %date(%trim(attrval) : *ISO);
               endsl;
             enddo;

             //  Base64 decode the pdf
             retlen = apr_base64_decode(PDFData : TmpValue);

             //  Create directory for this truck if it doesn't exist.
             Filename = '/home/Driver Logs/' + Truck;
             if syscall('crtdir dir(''' + Filename + ''')' : 'CPFA0A0') <> '';
               //  Send error message
               dsply ('Error creating log directory for ' + Truck) 'SCOTT';
               return;
             endif;

             //  Store PDFData to an ifs file.
             Filename += '/Log' + %char(LogDate : *ISO0) + '.pdf';
             unlink(Filename);
             fd = open(Filename :
                       O_WRONLY+O_CREAT+O_CODEPAGE:
                       S_IRUSR + S_IWUSR + S_IXUSR
                       + S_IRGRP + S_IXGRP
                       + S_IROTH + S_IXOTH : 819);
             if fd < 0;
               EscErrno(errno);
               dsply ('RANDRTVLOG Write PDF Error: ' + %char(errno)) 'SCOTT';
             endif;


             if write(fd: %addr(PDFData): retlen) < retlen;
               err = errno;
               callp close(fd);
               EscErrno(err);
             endif;

             callp close(fd);

           when name = 'Vehicle';
             Truck = %trim(value);

           when name = 'PDFData';
             PDFData = value;
             TmpValue = %subst(PDFData : 1 : %len(value));

           when name = 'TotalRecordCount';
             QueueDepth = %int(%trim(value));

         endsl;

      /end-free
     P                 E
                                

Scott

-----Original Message-----
From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Michael Ryan
Sent: Wednesday, April 22, 2015 10:08 AM
To: HTTPAPI and FTPAPI Projects
Subject: Base64 Decoding/Raw vs. Post

Ok...I need to receive a Base64 document in an XML tag. I'm currently using http_url_post_raw and converting to EBCDIC, but that's not going to work, is it? Dumb question: if I use http_url_post_xml to get the Base64 data, that will still be in binary, right? And then I can decode it and write it to a file, right?

Anyone have an example? Thanks!
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------