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

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
   <[1]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: [2]ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
   [mailto:[3]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:
     [4]http://www.scottklement.com/mailman/listinfo/ftpapi
     --------------------------------------------------------------------
     ---

   --
   R.

References

   1. mailto:SMildenberger@xxxxxxxxxxxxxxxxxx
   2. mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
   3. mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
   4. http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------