Hello,
My goal is to have a webform with a link for the client to download a PDF, this PDF should come from a HTTP request from a server in our network and I will display it via webform to the public.
I'm not able to receive the full response for a PDF on an HttpClientRequest, it seems that everytime the pdf is incomplete, if I try with a website URL the response is longer and ok, but never with PDF.
I've try all kinds of hearders but with no success.
Here's a sample of the code:
Code |
---|
var url = 'https://www.soundczech.cz/temp/lorem-ipsum.pdf'; var http = new HttpClientRequest(url); http.method = "GET"; http.header["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36"; http.header["Accept"] = "application/pdf"; http.header["Content-Type"] = "application/pdf;charset=utf-8"; http.header["accept-encoding"] = "gzip, deflate"; http.execute(); logInfo(http.response.body); pdf = http.response.body;; |
The logInfo goes to web@default and the pdf is displayed on webpage.
Thanks for any help
Solved! Go to Solution.
Hello,
I managed to do this in another way (will share how, in case more people need it).
I was using the code in a JavaScript and using a webApp variable to pass the content from the JS to the page item.
This was solved by executing the javascript code in the page itself.
Apparently we can't store the result of a PDF in a var because there are some EOF text that can corrupt the result. So the final code is:
<head>
<%
var url = 'https://www.soundczech.cz/temp/lorem-ipsum.pdf';
var http = new HttpClientRequest(url);
http.method = "GET";
http.execute();
%>
</head>
<body style="" class="">
<p>Stuff:</p>
<a href="data:application/pdf;base64, <%= http.response.body.toBase64() %>" target="_blank" download=""> pdf </a>
This will enable the user to download the PDF.
Hi jferreira,
Please may you achieve the same again but with try catch instructions, and share the detailed errors (web.log, ctx in debug mode, etc).
There could be many issues:
You can also use the alternative simple way getUrl() function, but it won't resolve your issue if it is a network issue or security issue...
http://docs.campaign.adobe.com/doc/AC/en/jsapi/f-getUrl.html?hl=geturl
One more thing, if you have access to curl, please run it to check if the access is right.
Or if you have access to system exec command, do the wget equivalent:
http://docs.campaign.adobe.com/doc/AC/en/jsapi/f-execCommand.html?hl=wget
Regards
J-Serge
Views
Replies
Total Likes
Hello,
Thanks for the tips.
I'm now testing on a workflow because it's faster. The log I see is something like this:
The feeeling I have is that the response it not complete or there's something limiting the response. This was obtained with the getUrl() function, seems the output it's the same.
About permissions, I would say it's not the case because I can receive partial answer, so it connects successfully.
Although if you think it's an issue on serverConf, maybe I can give it a try.
Thanks
Views
Replies
Total Likes
Hi J Ferreira,
You are right, because the transfer starts successfully even though not complete, it is not a question of permissions/network access, sorry for my bad suggestions in your case.
In your workflow, did you put try/catch as well?
To my mind, it should be a question of some specific characters treated as end of file/stopping transmission or something like that, because pdf is binary file, not text file.
The same for logInfo() perhaps broken as well?
Not sure, sorry.
Please read in JSAPI documentation the memoryBuffer function and manipulation for such binary contents, probably you would save the content in a file (without logInfo) and then compare the saved file with the original file.
But I wonder, why must be read the pdf content and display it in a webApp (I guess with an iframe)? Won't it be possible to use an iframe with the file with argument and the standard Adobe Reader web object doing the job for displaying the content?
Regards
JS
Views
Replies
Total Likes
I tried with a try catch but the end result is the same.
I have the same feeling, there should be a set of chars that ends the stream, be it in logInfo or displaying it in the page.
I think I'll have to try another approach.
I must read the PDF because we have it in a webserver in the network that is not public, so I need to grab the PDF and make it public.
Thank you for the help
Views
Replies
Total Likes
Ok so if it is the only reason, you should get the file (urlGet), saving it "locally" on the Adobe Campaign res specific sub-folder of your choice, then you expose this file to the webform link/button.
Using MD5 for naming the "local" file and so reduce security issue for such public folder.
Then cleansing the subfolder either immediately or not.
Perhaps someone else could give other advices for doing the same easily.
Regards
JS
Views
Replies
Total Likes
This can be a good solution!
Can you provide a quick example?
Thank you so much
Views
Replies
Total Likes
Hello,
I managed to do this in another way (will share how, in case more people need it).
I was using the code in a JavaScript and using a webApp variable to pass the content from the JS to the page item.
This was solved by executing the javascript code in the page itself.
Apparently we can't store the result of a PDF in a var because there are some EOF text that can corrupt the result. So the final code is:
<head>
<%
var url = 'https://www.soundczech.cz/temp/lorem-ipsum.pdf';
var http = new HttpClientRequest(url);
http.method = "GET";
http.execute();
%>
</head>
<body style="" class="">
<p>Stuff:</p>
<a href="data:application/pdf;base64, <%= http.response.body.toBase64() %>" target="_blank" download=""> pdf </a>
This will enable the user to download the PDF.
Views
Likes
Replies
Views
Likes
Replies