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

RE: Base64 decode of a PNG file



Actually I was thinking of removing the O_TEXTDATA from the open of the output file not the input file which is what I think you changed, I didn't notice it was in both places.  The output file if a .png so it isn't text.  You want to leave the O_TEXTDATA on the input file as your debug shows you getting the proper input with that there.

Scott Mildenberger


-----Original Message-----
From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Radu Botescu
Sent: Monday, February 23, 2015 9:51 AM
To: HTTPAPI and FTPAPI Projects
Subject: Re: Base64 decode of a PNG file

Hi Scott,

Thank you for your answer.

I've modified the program and deleted O_TEXTDATA from all the instructions.

Now I have the 'famous' message:

Unable to decode character at position 1. (Char=x'69')

I put the program in debugg and saw that:

1. WHITOUT O_TEXTDATA in opening the "fedex.bin" I have the above error.

Also my InputData is like this

EVAL InputData
INPUTDATA =
          ....5...10...15...20...25...30...35...40...45...50...55...60
     1   'Ñîâ!êÏ.åÅ?    +ëíÇáíÅ  âìÅ   ! {    â{Ë°,    á%á{îêÍÀ'
    61   'ÃÏ,ß+Äͧë(/øËÃ{áÄì/!Ïï§Î̧ãøãìÇÍï <âÂÏ/Ãâã%'
   121   'ñß_ìù{:+§ä(+äÎĵ{áëáÁ.µÏÅä@+ÊÅ(§øù/:/<<_</µ'
   181   '<êßä §Àî.°Êî:ñÇùì,/îïåÊÎÎÁî++>+áÀìË:ÉÍ,ùùÀìî,&'
   241   'ìÃÈÃÑ<îÌÏÑ:äÄìÁ\Î %,ïÎ\ì,ß?Èù:§+<ê@Î?ÏÇ_Ë,À(§<Í/ø'
   301   'ìùùâ/:Ä>ê>ÑÁÏ>îáÊ,ÁÍíãÏ!+åïïÎÎ/äÈ°?Í°ÑâÃë_>:ѧ.Ì'
   361   'Ï<ÉïÃ(\ÍãÊÌëäîÁ§§ÉÊ(ã ÍÁÅ/Â!ä{Éä\ùÉ@°ÂʵâÊÅ<{: '
   421   'Î/âãê>ÂÍ@+Ñ?ï\ÇÁ°/íË°ïãáìÎã\Êå<ã?ÍÈ(_ï!>ÍÏÈ:>.Î'
   481   'ÌÂïÍÅ:ÁêÑíÄ_å\ÇìÂ%âËÈÀÑÂ?Ìå!+Á\ãÏÎÈ!ÊÃÁÀÌÎ_áî>Íá'
   541   'µÊï<î@.@>%ÌÀ&µ%åËĵÍ:ìÉ&@/ÍÃ,å/%!µÅÇ>_/\Ì?À<,>°'
   601   'ß_!í?}ßî@!ÍËËëî%ÎÀ\íÈ,ä,Ï\Ï&ñÂ{&ÏɧïîËê°ì§(Ïå'


2. WITH O_TEXTDATA in opening the "fedex.bin" I do not have any error but the empty png file.

Also my InputData is like this

EVAL InputData
INPUTDATA =
          ....5...10...15...20...25...30...35...40...45...50...55...60
     1   'iVBORw0KGgoAAAANSUhEUgAABXgAAAO2AQAAAAB6QsJkAAA8AElEQVR42u3d'
    61   'f2wk150Y+Ncu3ZSMa09psf9QEcXaOwWZvxbb48ZFpFXhu4WALBbwaf67BFl7'
   121   'I90Y4mXj4QzN1ZCM211N01Cvc1y27QESEeKy/wgC44DNrgMZpja0zaLLmLay'
   181   'LRYCAZdVKJrV2zI7hjXka9V6WG0+1rvve1VNNn/N8EdXszqukjjdXV0kP118'
   241   '9X3f76tfiLVxwiz0CcXe2HvA6/lkWvH0XkYotjzZNLRDv5owh1mskdMZLuap'
   301   'XjjBazc8nRniewnVErkeuUFwON6G4WWv6va4Ct5Jo189uJiBfS9m6nziZK8x'
   361   'wL0qW2fMHu8FrxSCV/e9ZZq5r29MFAue/gabOCQqCH+jqDJ1bryBr53gLQzA'
   421   'v1aBFRnbuD7Nio163WHheJ358a/UsJW2FE/XvFHr4GLFou8tMmWOnuwtznKv'
   481   'xb1WugzeRiU875cmGHhXblB2stdi1+boxGO8NeHFwvtOrf3ed8xvmEVn/u6E'
   541   'yr0WLVDKDnlx+d6Py/lGscyuzXqP8DaufkG3alOyghnm7aHx/od6273Lk7nJ'
   601   'Ym0+O64UoT1YVD7O+5u5ssS96VlvdH4UtkCkwHwPIbQPwqZ75WVs1RJXZMwG'

which is exactly what I see by opening the file (in Windows explorer or by wrklnk). And the same is in the xml file received from FEDEX.

For sure there is something wrong in my program but I have no ideea what...

Radu


On Mon, Feb 23, 2015 at 5:19 PM, Scott Mildenberger < SMildenberger@xxxxxxxxxxxxxxxxxx> wrote:

> I am pretty sure that you don't want the O_TEXTDATA when you open the 
> IFS file.
>
> Scott Mildenberger
>
> -----Original Message-----
> From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:
> ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Radu Botescu
> Sent: Monday, February 23, 2015 9:10 AM
> To: HTTPAPI and FTPAPI Projects
> Subject: Base64 decode of a PNG file
>
> Hello,
>
> I call a Fedex webservice in order to retrieve a document in PNG 
> format and print it.
> But this document is base64 encoded.
>
> Thanks to Scott's HTTPAPI I can call the webservice and parse the 
> right XML element into a file in IFS.
>
> So at this time I have a binary file in IFS:
> - /tmp/fedex.bin ==> CCSID 819
>
> - if I  copy/paste it in a online internet decoder I have no problem 
> in getting back the PNG
>
> - but on the AS400 I have no luck:
>   - I've tried the openssl (opened QSHELL and put "openssl base64 -d 
> -in /tmp/fedex.bin -out /tmp/fedex.png  ") ==> the result is a 
> fedex.png with 0 bytes;
>
>   - I've tried Scott's base64_decode (reading the IFS and writing the 
> result in IFS)  ==> same result, a fedex.png with 0 bytes;
>
>
> What I'm doing wrong...? :(
>
> Thank you in advance for your help.
>
> Here below the program using Scott's base64_decode (sorry in advance 
> if my code is a mess...it is only a draft version..proof of concept kind of...):
>
> H DFTACTGRP(*NO) BNDDIR('BASE64':'QC2LE')
>
>
>
>  /copy BASE64_H
>
>  /copy httpapi_h
>
>  /copy ifsio_h
>
>
>
>
>
> D BASE64DATA      s             72A   DIM(43) CTDATA PERRCD(1)
>
> D ReportError     PR
>
>
>
> D IFS_file2Var    pr         65535a   varying
>
> D  pFile                       256a   value
>
>
>
> D InputData       s          32767A   varying
>
> D OutputData      s          32767A   varying
>
> d decdata         s          32764a
>
> d decoded         s          32764a
>
> d declen          s             10i 0
>
> d len             s             10i 0
>
> D outputfile      s            200A
>
> D outfile         s             10I 0
>
> d rc              s             10i 0
>
> d i               s             10i 0
>
> D fd              S             10I 0
>
>
>
>       // Declare the files
>
>       InputData = IFS_file2Var('/tmp/fedex.bin');
>
>       len = %len(InputData);
>
>
>
>       outputfile = '/tmp/fedex.png';
>
>
>
>       // Prepare the OUT file
>
>       fd = open(outputfile
>
>                     : O_WRONLY+O_CREAT+O_TRUNC+O_CCSID
>
>                     : S_IRGRP + S_IWGRP + S_IXGRP +
>
>                        S_IRUSR + S_IWUSR + S_IXUSR
>
>                     : 819);
>
>       callp close(fd);
>
>      fd = open(outputfile:O_WRONLY+O_TEXTDATA);
>
>      // decode InputData
>      declen = base64_decode(%addr(InputData : *DATA )
>                            : len
>                            : %addr(OutputData : *DATA )
>                            : %len(OutputData));
>
>      // write it
>      callp write(fd: %addr(OutputData): %len(OutputData));
>      callp close(fd);
>
>      *inlr = *on;
>
>  **** IFS ==> variable pgm
> P IFS_file2Var    b                   export
> D IFS_file2Var    pi         65535a   varying
> D  pFile                       256a   value
>
> D open            pr            10i 0 extproc('open')
> D  filename                       *   value options(*string)
> D  openflags                    10i 0 value
> D  mode                         10u 0 value options(*nopass)
> D  codepage                     10u 0 value options(*nopass)
> D  creatcnvid                   10u 0 value options(*nopass)
>
> D read            pr            10i 0 extproc('read')
> D  handle                       10i 0 value
> D  buffer                         *   value
> D  bytes                        10u 0 value
>
> D close           pr            10i 0 extproc('close')
> D  handle                       10i 0 value
> D data            s          65535a
> D bytesRead       s             10i 0
> D handle          s             10i 0
> D rc              s             10i 0
> D O_RDONLY        c                   1
> D O_TEXTDATA      c                   16777216
>
>
>
>    handle = open(%trim(pFile): O_RDONLY+O_TEXTDATA);
>    if handle < 0;
>      // something is wrong
>       return '';
>    endif;
>      bytesRead = read(handle: %addr(data): %size(data));
>      if bytesRead <= 0;
>      return '';
>      endIf;
>      rc = close(handle);
>
>      return %trim(data);
>
>
> P                 e
> ----------------------------------------------------------------------
> - This is the FTPAPI mailing list.  To unsubscribe, please go to:
> http://www.scottklement.com/mailman/listinfo/ftpapi
> ----------------------------------------------------------------------
> -
>



--
R.
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------