× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



The reason you needed the +2 on the %addr() of a varying length character variable, is that %addr() points at the first byte of the memory space the variable occupies. The first two bytes of that space is the length of the value. Depending on the max length of the variable, it could be 4 bytes, so using %ADDR(varying-length variable : *DATA) is better if you have a version of the compiler that supports it.

Since you are using %addr(binaryImage) + 2 for what I am assuming is the output variable, you probably are not setting the length of that variable length field, so the program thinks it is 0 even if you put something there. Variable length strings operate quickly because the computer ignores anything out past the length (stored in the first 2 or 4 bytes of the variable's memory space). You can put stuff there by using a pointer to address it, but if the length portion is 0, the variable is empty.

Mark Murphy
STAR BASE Consulting, Inc.
mmurphy@xxxxxxxxxxxxxxx


-----Michael Schutte <mschutte369@xxxxxxxxx> wrote: -----
To: "RPG programming on the IBM i / System i" <RPG400-L@xxxxxxxxxxxx>
From: Michael Schutte <mschutte369@xxxxxxxxx>
Date: 01/08/2016 11:37AM
Subject: BASE64 Encoded Character String to IFS.


I'm back to this project. A few years ago, I requested information. The
information provided was great at the time, however we were able to get the
USPS to send back the tracking number and just barcode it on our own
label. So taking an image and printing it on the printer was no longer
needed.

Now the account wants to change to UPS. UPS requires us to print their
label. I have to believe that someone has this working.

So here's what I have so far. FYI, the type of image is GIF. I know this
for certain this time. The XML document told me so. :-)

Originally...

D LABELIMAGE S 65535 VARYING
D binaryImage S 65535 VARYING

After getting the encoded Base64 string from an XML document. I ran this
code.
base64_decode(%addr(LabelImage)
:%Len(LabelImage)
:%addr(binaryImage)
:%size(binaryImage));

But this was failing saying that it couldn't decode x'9F'. I remembered
back to my days using WrtNoSection in CGIDEV2 that we had to add 2 to the
%Addr. I never understood why but I changed the code like so.

base64_decode(%addr(LabelImage) + 2
:%Len(LabelImage)
:%addr(binaryImage) + 2
:%size(binaryImage));

This time base64_decode didn't crash however, it appears that binary image
was empty in debug.

I was thinking that maybe it appeared that way because it was binary. Not
really sure how its supposed to look as this is really my first time using
this.

So I continued and tried to write the binaryimage to an IFS file. This
again could be wrong, I'm just not sure what exactly I need to do.

fd = open('/home/mschutte/testups.gif'
: O_WRONLY + O_CREAT + O_TRUNC
: S_IRUSR + S_IWUSR + S_IRGRP);
callp write(fd: %addr(binaryimage): %len(binaryimage));
callp close(fd);

I also tried adding the 2 to the %Addr. But the file on the IFS is empty.
There has to be someone out there that's done this right? I hope!

I'm using Scott Klement's tools, Base64, LIBHTTP, and IFS stuff.

I'm coming up empty finding examples on the web.

-- this was original posted to MIDRANGE and denied.

So here's an update. I've found an alternative.

rc = Apr_Base64_Decode_Binary(pathname:%addr(LabelImage));

When finished rc is zero. So it appears there are no errors, but I'm not
getting a file. Any suggestions on either method?

Thank you

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.