If you want to return the PDF as part of a JSON object I think you're going to have to encode it as base-64 first, you can't just include arbitrary character/binary data.
________________________________
From: WEB400 <web400-bounces@xxxxxxxxxxxx> on behalf of Toni Schaake <Toni.Schaake@xxxxxxxxxxxxxx>
Sent: 30 October 2018 14:54
To: Web Enabling the IBM i (AS/400 and iSeries)
Subject: Re: [WEB400] Return PDF in Rest Service
Hi Bradley,
Thank you for your prompt response.
The CCSID of the PDF is 819 on the IFS.
I'm building a JSON Object to return to the client. It looks like this:
[
{
"UploadStatus": "A",
"UploadMessage": "Biometric Info Captured",
"HHSCore": "RED"
},
{
"ResponseDocument": "%PDF-1.7\n%äã�Ò\n4......... ==> this data is corrupted.
}
]
I was hoping to load the PDF with yajl_addCharStmf('ResponseDocument' : DocPath: ErrMsg). Docpath is where the PDF Doc is stored on the IFS.
yajl_writeStdout(sts: msg); does not allow for content-type of application/pdf, and I need Content-Disposition in the header as well, hence the need to do QtmhWrStout.
Best Regards,
Toni
-----Original Message-----
From: WEB400 <web400-bounces@xxxxxxxxxxxx> On Behalf Of Bradley Stone
Sent: 30 October 2018 15:17
To: Web Enabling the AS400 / iSeries <web400@xxxxxxxxxxxx>
Subject: Re: [WEB400] Return PDF in Rest Service
What Code page is the PDF in your IFS?
What format is the PDF returned to client 2? It looks like a straight PDF
file... so why are there yajl functions in it and building arrays, etc?
Where are you loading the PDF in this code? Is it already in jsonBuf? How did it get there? From other code not in the sample source?
If you were to use something like eRPG SDK or CGIDEV2 to return the PDF document it would be a lot easier. Write out headers, load the PDF as the template, and write it out. eRPG example:
#startup();
#writeTemplate('stdPDFheader.erpg'); <--- this contains
headers like Content-type: application/pdf with 2 new lines
#setCCSIDStdOut(1208);
#writeTemplate(yourPDFFile);
#cleanup();
*INLR = *on;
Bradley V. Stone
https://nam02.safelinks.protection.outlook.com/?url=www.bvstools.com&data=02%7C01%7C%7Cb64f74280d4148c9225308d63e6f3983%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636765044753945338&sdata=Amv%2FJEwILMmpGRbqFoRrGPwiBDp6GTjWCHmLCpv%2Fkww%3D&reserved=0
MAILTOOL Benefit #6 <
https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.bvstools.com%2Fmailtool.html&data=02%7C01%7C%7Cb64f74280d4148c9225308d63e6f3983%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636765044753945338&sdata=U%2Fqu0gNZ20BaSvF353ZZwPuWjw5YOhYOAdvoY0K69ls%3D&reserved=0>: Easily send group emails with Distribution Lists
On Tue, Oct 30, 2018 at 8:01 AM Toni Schaake <Toni.Schaake@xxxxxxxxxxxxxx>
wrote:
Hi there,
I'm having great difficulty in returning a PDF Document in a REST
Service request.
Background:
I'm facilitating a Webservice between 2 External parties
I receive a JSON request from Client 1, parse the info, call an API
(Via Scott's HTTPAPI) on Client 2's Systems, receive the response as a
PDF Document which I store on the IFS.
Now I need to pass this PDF Document back to Client 1 as a response to
their API call, and this is where I'm getting Garbage in the PDF Document.
Code Snippet:
yajl_genOpen(*on);
yajl_beginArray();
yajl_beginObj();
yajl_addChar('UploadStatus' : 'A');
yajl_addChar('UploadMessage' : %Trim(RspString));
yajl_addChar('HHSCore' : %Trim(w_HHSCore));
yajl_endObj();
yajl_beginObj();
yajl_addCharStmf('ResponseDocument' : DocPath: ErrMsg);
yajl_endObj();
yajl_endArray();
sts = 200;
// This is the response I log for error\troubleshoot\later
investigations etc.
Response = '[{"UploadStatus":"A",' +
'"UploadMessage:"' +%Trim(RspString) + '",' +
'"HHSCore":"' + %Trim(w_HHSCore) + '"},{'+
'"ResponseDocument":"' + %Trim(Docpath) + '}]';
doLogging();
// the following code acts like yajl_writeStdout. I need
content-type to be different
rc = yajl_getBuf( jsonBuf: jsonSize );
Headers = 'Status: ' + %editc(sts:'X') + CRLF +
'Content-type: application/pdf' + CRLF +
// 'Content-type: application/json charset=utf-8' + CRLF +
// 'Content-type: application/octet-stream' + CRLF +
// 'Transfer-Encoding: identity' + CRLF +
'Content-Encoding : gzip' + CRLF +
'Content-Disposition: attachment; filename=' +
%Trim(w_File) + CRLF + CRLF;
QtmhWrStout ( %addr(Headers) + 2 : %len(Headers) : APIError );
offset = 0;
dow jsonSize > 0;
length = jsonSize;
if length > ChunkSize;
length = ChunkSize;
endif;
QtmhWrStout ( jsonBuf + offset : length : APIError );
jsonSize -= length;
offset += length;
enddo;
//yajl_writeStdout(sts: msg); yajl_genClose();
This runs fine and returns the Document, but the PDF is all garbage.
I'm not too sure if yajl_addCharStmf() is the correct procedure to use.
I'm using both Postman and SOAPUI for testing.
Kind Regards,
Toni Schaake.
--
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://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.midrange.com%2Fmailman%2Flistinfo%2Fweb400&data=02%7C01%7C%7Cb64f74280d4148c9225308d63e6f3983%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636765044753945338&sdata=rQewkQE9icRCtXYkPt3jPbGE59BE0Srxa4faasuoBJI%3D&reserved=0
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Farchive.midrange.com%2Fweb400&data=02%7C01%7C%7Cb64f74280d4148c9225308d63e6f3983%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636765044753945338&sdata=SdOZ3ZyVzJ5t9k11l6hSuBxrxglgOkQOG0YYeHyq7LE%3D&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://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.midrange.com%2Fmailman%2Flistinfo%2Fweb400&data=02%7C01%7C%7Cb64f74280d4148c9225308d63e6f3983%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636765044753945338&sdata=rQewkQE9icRCtXYkPt3jPbGE59BE0Srxa4faasuoBJI%3D&reserved=0
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Farchive.midrange.com%2Fweb400&data=02%7C01%7C%7Cb64f74280d4148c9225308d63e6f3983%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636765044753945338&sdata=SdOZ3ZyVzJ5t9k11l6hSuBxrxglgOkQOG0YYeHyq7LE%3D&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://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.midrange.com%2Fmailman%2Flistinfo%2Fweb400&data=02%7C01%7C%7Cb64f74280d4148c9225308d63e6f3983%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636765044753945338&sdata=rQewkQE9icRCtXYkPt3jPbGE59BE0Srxa4faasuoBJI%3D&reserved=0
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at
https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Farchive.midrange.com%2Fweb400&data=02%7C01%7C%7Cb64f74280d4148c9225308d63e6f3983%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636765044753945338&sdata=SdOZ3ZyVzJ5t9k11l6hSuBxrxglgOkQOG0YYeHyq7LE%3D&reserved=0.
As an Amazon Associate we earn from qualifying purchases.