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



Hello,

I've talked to IBM and they indicated that you can't send binary data with IWS. This is also said in the documentation.
"A RESTful web service has the capability to return user defined content. That is, something other than XML or JSON. For example, a content type of text/html. In order for the web service implementation code to be able to do this, it must have one output parameter that is to be returned as a response, and the parameter must have a type of character. Note that you can even return binary images, assuming the web service implementation code encodes the image in the Base64 MIME content transfer encoding and the Content-Transfer-Encoding HTTP header is set to base64."

So I've changed my program to use Base64. It uses base64_encode from the HTTP API of Scott. https://www.scottklement.com/httpapi/

----------------------------------------------------------------------------------------------------

ctl-opt main(Main) pgminfo(*PCML:*MODULE) dftactgrp(*NO) actgrp(*new);
ctl-opt decedit('0,') datedit(*DMY.) option(*SRCSTMT:*NODEBUGIO);
ctl-opt bnddir('LIBHTTP/BASE64');

dcl-pr base64_encode uns(10);
*n pointer value; // Input
*n uns(10) value; // InputLen
*n pointer value; // Output
*n uns(10) value; // OutputSize
end-pr;

dcl-proc Main;
dcl-pi *N extpgm('TEST25');
Input char(8);
Output char(15728640);
httpstatus int(10);
httpheader char(100) dim(10);
end-pi;

dcl-s BLOBFILE sqltype(BLOB_FILE);
dcl-s BLOB sqltype(BLOB:15728640);
dcl-s length uns(10) inz;

exec sql
Set Option Commit = *NONE, CLOSQLCSR = *ENDMOD;

clear BLOBFILE;
BLOBFILE_fo = SQFRD;
BLOBFILE_name = '/Home/File1.pdf';
BLOBFILE_nl = %len(%trimr(BLOBFILE_name));
exec sql
set :BLOB = :BLOBFILE;

length = base64_encode(
%addr(BLOB_Data):
BLOB_Len:
%addr(Output):
%size(Output));

//Return the data base64 encoded
Output = %subst(Output:1:length);

httpstatus = 200;
httpheader(1) = 'Content-Type: application/pdf';
httpheader(2) = 'Content-Transfer-Encoding: base64';

//Or return HTML to decode and show in a browser
//Doesn't work with current IE and Edge. Maybe there's some more to do.
//Source: https://base64.guru/developers/javascript/examples/decode-pdf
Output = '+
<html>+
<body>+
<script>+
var obj=document.createElement(''object'');+
obj.style.width=''100%'';+
obj.style.height=''98%'';+
obj.data=''data:application/pdf;base64,' +
%subst(Output:1:length) + ''';+
document.body.appendChild(obj);+
</script>+
</body>+
</html>';

httpstatus = 200;
httpheader(1) = 'Content-Type: text/html';
httpheader(2) = 'Content-Transfer-Encoding: base64';

end-proc;

----------------------------------------------------------------------------------------------------

Greetings Jens

-----Ursprüngliche Nachricht-----
Von: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxxxxxxxx] Im Auftrag von Ottersberg, Jens
Gesendet: Montag, 8. Juli 2019 14:37
An: RPG programming on IBM i <rpg400-l@xxxxxxxxxxxxxxxxxx>
Betreff: AW: Sending File via IWS WebService with RPG

--
This is the RPG programming on IBM i (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related questions.

Help support midrange.com by shopping at amazon.com with our affiliate link: https://amazon.midrange.com

As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.