× 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.



...this is about the quickest and dirtiest code I can come up with that will convert your PDF into base-64, using embedded SQL. Be careful, there's no error checking or validation of any kind and I wouldn't use SQL to do the base64 encoding in production in this case because it's quite slow and can only encode chunk of 2732 bytes, the apr_base64_* APIs are almost certainly a better choice. I'm not familiar with the YAJL library, but as far as I can see, you have to pass a character string to it in this case and so you'd be limited to PDFs of about 3/4s of the size of the maximum RPG character field length (about 12MB).

**FREE
ctl-opt main(main);

dcl-proc main;
dcl-pi *N end-pi;

dcl-c CHUNK_SIZE 2732;
dcl-s fileName varchar(630);
dcl-s fileBlob sqltype(BLOB_LOCATOR);
dcl-s start int(10) inz(1);
dcl-s bytesLeft int(10);
dcl-s base64ChunkLen int(5);
dcl-s base64Chunk varchar(4096);
dcl-s base64doc varchar(16000000);

filename = '/document.pdf';

exec sql set :fileBlob = get_blob_from_file(:fileName);
exec sql set :bytesLeft = length(:fileBlob);

dow bytesLeft > 0;
base64ChunkLen = %min(CHUNK_SIZE: bytesLeft);
exec sql
set :base64Chunk = systools.base64encode(
substr(:fileBlob, :start, :base64ChunkLen)
);

base64doc += base64Chunk;
bytesLeft -= base64ChunkLen;
start += base64ChunkLen;
enddo;

// yajl_...
// yajl_addChar('document': base64doc);
// yajl_...

end-proc;


________________________________
From: WEB400 <web400-bounces@xxxxxxxxxxxx> on behalf of Toni Schaake <Toni.Schaake@xxxxxxxxxxxxxx>
Sent: 05 November 2018 10:53
To: Web Enabling the IBM i (AS/400 and iSeries)
Subject: Re: [WEB400] Return PDF in Rest Service

Hi All,

Thank you all for the advice.

I've made the changes to encode the PDF to Base64, but still no luck.

Does anybody have some sample code, as I'm really stuck here and need to get it to work ASAP.

I'm using Scott's YAJL tools, and HTTPAPI handle the request to the server where the PDF originates from. (Using Http_Req(), also tried http_Stmf()).

Thank you in advance,

Toni Schaake.

-----Original Message-----
From: WEB400 <web400-bounces@xxxxxxxxxxxx> On Behalf Of Charles Wilt
Sent: 31 October 2018 17:28
To: Web Enabling the AS400 / iSeries <web400@xxxxxxxxxxxx>
Subject: Re: [WEB400] Return PDF in Rest Service

On Wed, Oct 31, 2018 at 1:29 AM Toni Schaake <Toni.Schaake@xxxxxxxxxxxxxx>
wrote:

I understand that the PDF, when viewed as raw data is already
"garbage", but in my test the "garbage" does not look the same as the
original saved PDF. (Hope you understand what I mean here).



Probably your code (and/or the i) didn't treat the document as binary, thus it was translated from to ASCII

Make you write/read from the IFS as binary, not text.

Charles
--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing list To post a message email: WEB400@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.midrange.com%2Fmailman%2Flistinfo%2Fweb400&amp;data=02%7C01%7C%7C36d022ea4dbc4e8ff7ef08d64304972f%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636770084325948223&amp;sdata=Lrwv%2B9ypqprq6aZ55LQ4r6l3D47OAHT1oUdt63HtGiY%3D&amp;reserved=0
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Farchive.midrange.com%2Fweb400&amp;data=02%7C01%7C%7C36d022ea4dbc4e8ff7ef08d64304972f%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636770084325948223&amp;sdata=4BoURHJ2RZlPaUWoSo1ZIDuWMDHmFGf39SYVwXQOGko%3D&amp;reserved=0.

--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing list
To post a message email: WEB400@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.midrange.com%2Fmailman%2Flistinfo%2Fweb400&amp;data=02%7C01%7C%7C36d022ea4dbc4e8ff7ef08d64304972f%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636770084325948223&amp;sdata=Lrwv%2B9ypqprq6aZ55LQ4r6l3D47OAHT1oUdt63HtGiY%3D&amp;reserved=0
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Farchive.midrange.com%2Fweb400&amp;data=02%7C01%7C%7C36d022ea4dbc4e8ff7ef08d64304972f%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636770084325948223&amp;sdata=4BoURHJ2RZlPaUWoSo1ZIDuWMDHmFGf39SYVwXQOGko%3D&amp;reserved=0.


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.