I have a Web App running on the same machine as 4D Sever and all requests to 4D
are done over localhost. I am currently displaying PDFs by having the Web App
get the path to the pdf file from 4D then serve the file to it’s viewer in the
browser.
This all works fine, but after some testing have found that it is significantly
slower than serving the blob directly from 4D with WS SEND BLOB. I have only
been able to get this to work if I make the request for the pdf directly from
the browser, not via the Web App. In other words using the address bar of the
browser or the HTML viewer of the Web App in the browser. The problem is that
this exposes the request including the path to the PDF on the server.
I need to have the Web App on the server make the request to 4D over local host
then serve the PDF to the web app’s viewer in the browser. The closest I could
get to being successful was by having the web app create a simple web page with
the returned data and send the page to the web app’s viewer in the browser…
//web app request
pdfBlob = socket1.Get("http://127.0.0.1:9000/getDocumentBlob?path="+docPath,
30) //send request to 4D
pdfBlob = EncodeBase64(pdfBlob,0)
//create the web page
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body. TESTING TESTING>
<object data="data:application/pdf;base64,pdfBlob ” type="application/pdf"
width="100%" height="675px">
</object>
</body>
</html>
//send the page to the viewer in the browser
//4D response:
$path:=Convert path POSIX to system(WebRequestGetFormField ("path"))
C_BLOB($blob)
DOCUMENT TO BLOB($path;$blob)
WEB SEND BLOB($blob;"application/pdf")
All I get, however, is “TESTING TESTING” followed by a grey block where the pdf
would be displayed. It has been suggested to me that the problem may be
encoding and the following was suggested for encoding the response…
pdfBlob = EncodeBase64(DefineEncoding(pdfBlob ,Encodings.UTF8),0). //still a
grey block
Not completely understanding how encoding really works I am not sure how to ask
this, but what encoding is 4D using to send the PDF blob. Or can somebody
explain why this doesn’t work.
Thanks,
John
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive: http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub: mailto:[email protected]
**********************************************************************