By the way, if you don't want to use YAJL, another(easier!) option is to use SQL, which can naively build JSON objects and might help you overcome the 12M limit, below is a small example.

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

dcl-s jsonDoc sqltype(CLOB: 32767);
dcl-s base64doc sqltype(CLOB: 32767);

dcl-s status varchar(10) inz('A');
dcl-s message varchar(256) inz('Biometric Info Captured');
dcl-s hhscore varchar(10) inz('RED');


exec sql set :base64doc = 'dsdslkflkfdslkfgdgdg';

exec sql
set :jsonDoc = json_object(
'UploadStatus': :status,
'UploadMessage': :message,
'HHSCore': :hhscore,
'document': :base64doc
);

end-proc;

Also, the format of your output JSON object looked odd to me:
[
{
"UploadStatus": "A",
"UploadMessage": "Biometric Info Captured",
"HHSCore": "RED"
},
{
"ResponseDocument": "%PDF-1.7\n%äã�Ò\n4......... ==> this data is corrupted.
}
]

..is an array of two different shaped objects, I would expect it to look more like:

{
"UploadStatus": "A",
"UploadMessage": "Biometric Info Captured",
"HHSCore": "RED",
"ResponseDocument": {
"type": "application/pdf",
"data": "ASbdhbesjwwmsmewejwewee=="
}
}
________________________________
From: WEB400 <web400-bounces@xxxxxxxxxxxx> on behalf of Toni Schaake <Toni.Schaake@xxxxxxxxxxxxxx>
Sent: 05 November 2018 13:52
To: Web Enabling the IBM i (AS/400 and iSeries)
Subject: Re: [WEB400] Return PDF in Rest Service

Hi Tim,

Thank you for the reply.

I did use the online encoder as mentioned in your previous reply. The data is the same after encoding.

Now I need to get that data into the JSON String.

I'm thinking of building the reply string without using YAJL, and writing it to the webserver with StdOut.

Best Regards,

Toni.

-----Original Message-----
From: WEB400 <web400-bounces@xxxxxxxxxxxx> On Behalf Of Tim Fathers
Sent: 05 November 2018 14:04
To: Web Enabling the IBM i (AS/400 and iSeries) <web400@xxxxxxxxxxxx>
Subject: Re: [WEB400] Return PDF in Rest Service

...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://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.midrange.com%2Fmailman%2Flistinfo%2Fweb400&amp;data=02%7C01%7C%7C4ee35fe37de74a285d4308d6431d9238%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636770191610576441&amp;sdata=FSR%2FhceiIGAWhskEDX1kpyUAuMDqABEvwP99W%2F3beKo%3D&amp;reserved=0
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at https://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Farchive.midrange.com%2Fweb400&amp;data=02%7C01%7C%7C4ee35fe37de74a285d4308d6431d9238%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636770191610576441&amp;sdata=GRCnI9t3kkgyeD62eWf9Cb626jYZPGU6dHk8DM8uuVQ%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://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.midrange.com%2Fmailman%2Flistinfo%2Fweb400&amp;data=02%7C01%7C%7C4ee35fe37de74a285d4308d6431d9238%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636770191610576441&amp;sdata=FSR%2FhceiIGAWhskEDX1kpyUAuMDqABEvwP99W%2F3beKo%3D&amp;reserved=0
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at https://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Farchive.midrange.com%2Fweb400&amp;data=02%7C01%7C%7C4ee35fe37de74a285d4308d6431d9238%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636770191610576441&amp;sdata=GRCnI9t3kkgyeD62eWf9Cb626jYZPGU6dHk8DM8uuVQ%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://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.midrange.com%2Fmailman%2Flistinfo%2Fweb400&amp;data=02%7C01%7C%7C4ee35fe37de74a285d4308d6431d9238%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636770191610576441&amp;sdata=FSR%2FhceiIGAWhskEDX1kpyUAuMDqABEvwP99W%2F3beKo%3D&amp;reserved=0
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at https://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Farchive.midrange.com%2Fweb400&amp;data=02%7C01%7C%7C4ee35fe37de74a285d4308d6431d9238%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636770191610576441&amp;sdata=GRCnI9t3kkgyeD62eWf9Cb626jYZPGU6dHk8DM8uuVQ%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://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.midrange.com%2Fmailman%2Flistinfo%2Fweb400&amp;data=02%7C01%7C%7C4ee35fe37de74a285d4308d6431d9238%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636770191610576441&amp;sdata=FSR%2FhceiIGAWhskEDX1kpyUAuMDqABEvwP99W%2F3beKo%3D&amp;reserved=0
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Farchive.midrange.com%2Fweb400&amp;data=02%7C01%7C%7C4ee35fe37de74a285d4308d6431d9238%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636770191610576441&amp;sdata=GRCnI9t3kkgyeD62eWf9Cb626jYZPGU6dHk8DM8uuVQ%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.