Hi,
I'm using base64_encode to work with a pdf file.
I read the pdf content with get_clob_from_file,
Then I put the encoded data in a json ( variable name : request)
and send it by http_req
But the pdf received is different than the original,
(It shows just the template model without the customized data)
Where could be the mistake ?
Thanks
This is an extract of the code:
dcl-s MioFile sqltype(clob:16773100);
dcl-s UTF8Data varchar(16773100) ccsid(1208);
dcl-s encoded char(16773100);
dcl-s request varchar(16773100);
exec sql
set :MioFile = get_clob_from_file(trim(:path));
UTF8Data = %Trim(MioFile);
outputlen = base64_encode(%addr(UTF8Data:*data)
: %Len(UTF8Data)
: %addr(encoded)
: %Len(encoded));
base64_encode of a pdf file
-
- Site Admin
- Posts: 856
- Joined: Sun Jul 04, 2021 5:12 am
Re: base64_encode of a pdf file
I don't know what you mean by "template model without the customized data". I'm guessing its something specific to your particular application where you are, perhaps, using some sort of template combined with custom data, and it happens to be the template part that's working -- but, as I'm completely unfamiliar, this is a wild guess.
Looking at your code, I'm surprised any of it works at all.
I'm not familiar with get_clob_from_file() the CLOB that it outputs contains data in EBCDIC?pargent70 wrote: ↑Wed Jan 29, 2025 8:16 amCode: Select all
dcl-s MioFile sqltype(clob:16773100); dcl-s UTF8Data varchar(16773100) ccsid(1208); dcl-s encoded char(16773100); dcl-s request varchar(16773100); exec sql set :MioFile = get_clob_from_file(trim(:path)); UTF8Data = %Trim(MioFile);
The reason I'm asking is the next line "UTF8Data = %Trim(MioFile)" seems designed to convert from EBCDIC to UTF-8. Why would you do that with a PDF? PDFs are binary documents, they aren't either EBCDIC or UTF-8, they are in PDF format. Running it through a translation table will corrupt the data.
Also, MioFile is the name of a data structure (from RPG's perspective) that contains multiple fields, including the length of the text... why would you want to trim, copy and convert all of those fields instead of just the data field? This makes no sense at all.
in fact, I'd strongly recommend NEVER using %TRIM with this sort of program. It is VERY harmful.
This part looks fine. Just be careful when you use 'encoded' that you handle the length properly using outputlen (and NOT %trim!!)pargent70 wrote: ↑Wed Jan 29, 2025 8:16 amCode: Select all
outputlen = base64_encode(%addr(UTF8Data:*data) : %Len(UTF8Data) : %addr(encoded) : %Len(encoded));