OE 11.3.2
How do I return a PDF via REST GET? Is it just a question of setting the application type in the header? My Apsv procedure is simply:
DEFINE OUTPUT PARAMETER pPDF AS MEMPTR NO-UNDO.
COPY-LOB FROM FILE "c:\temp\test.pdf" TO OBJECT pPDF.
and I mapped pPDF to the body.
This can't be that complicated but i'm sure I'm missing something small but significant.
You need to set the Content-Type and I always like setting the Content-Length.
Arrrghhh!!! So close and yet so far! I think my response headers are good but somehow the response gets encoded and not decoded...or something like that.
Here are my response headers:
Content-Length:83723
Content-Type:application/pdf
Date:Tue, 16 Sep 2014 16:56:14 GMT
Server:Apache-Coyote/1.1
I changed the content-type to "application/octet-stream" so that i could download the file and i saw that it is no longer the PDF that I sent. Instead it was a big long string of exactly the same length. For example, the original PDF starts "%PDF-1.4" while the downloaded file is one long line "JVBERi0xLjQNJeLjz9M..."
According to Progress Knowledge Base Article 000027108, to pass binary data via Web Services it is recommended that the Web Service be defined to pass the data via a LONGCHAR variable and the binary data should be BASE 64 encoded using the built-in BASE64-ENCODE function (the BASE64-DECODE function can be used to convert the LONGCHAR data back to binary data).
This code is taken from the base64-encode function help:
--------------------
DEFINE VARIABLE encdmptr AS MEMPTR NO-UNDO.
DEFINE VARIABLE encdlngc AS LONGCHAR NO-UNDO.
COPY-LOB FROM FILE "C:\myicons\test.ico" TO encdmptr.
encdlngc = BASE64-ENCODE(encdmptr).
COPY-LOB FROM encdlngc TO FILE "C:\myicons\testencode".
--------------------
Here is the code example from the DECODE help page:
--------------------
DEFINE VARIABLE decdmptr AS MEMPTR NO-UNDO.
DEFINE VARIABLE decdlngc AS LONGCHAR NO-UNDO.
COPY-LOB FROM FILE "C:\myicons\testencode" TO decdlngc.
decdmptr = BASE64-DECODE(decdlngc).
COPY-LOB FROM decdmptr TO FILE "C:\myicons\test.ico".
--------------------
And here is another example:
--------------------
DEFINE VARIABLE encdmptr AS MEMPTR NO-UNDO.
DEFINE OUTPUT PARAMETER pinum AS INT.
DEFINE OUTPUT PARAMETER StorageVariable AS LONGCHAR.
FIND FIRST filetest NO-LOCK.
ASSIGN pinum = filetest.num.
/* ASSIGN StorageVariable = BASE64-ENCODE(filetest.pdafile). */
COPY-LOB FROM filetest.pdafile TO encdmptr.
StorageVariable = BASE64-ENCODE(encdmptr).
--------------------
Hope this helps :-)
Thanks Vinko...but it did not work unfortunately. <sniff...>
The BASE64-ENCODE() seems to have been done automatically as the downloaded file is the same before and after implementing your suggestion. My guess is that since the REST Resource URI Editor in PDSOE sees that the parameter is of type java:byte it encodes automatically.
Perhaps then I need to tell the receiving browser that it must decode the payload?
Hi Paul,
Did you find a solution to your problem? Looking to do the same thing and kind of stuck :)
Cheers,
Simi