Aeneas McBurney
Posts: 0
Joined: Mon Jun 16, 2014 7:49 am

Appery.io instructions to generate a pdf from the front end

I have found an API that can do what I need. The code they supply in the java example is as below but this doesn't work if I paste to Appery server code

// These code snippets use an open-source library. http://unirest.io/java
HttpResponse response = Unirest.post("https://neutrinoapi-html-to-pdf.p.mas...")
.header("X-Mashape-Key", "Ppl1WgnoJwmshCodpzLiyCbzDwQZp1octpdjsnPyGB4TG8I5Ea")
.header("Content-Type", "application/x-www-form-urlencoded")
.field("content", "http://www.rfc-editor.org/news.html")
.field("html-width", 1024)
.field("margin", 10)
.field("title", "My Title")
.asBinary();

How do I call the above in Appery server code?

Aeneas McBurney
Posts: 0
Joined: Mon Jun 16, 2014 7:49 am

Appery.io instructions to generate a pdf from the front end

Hi,

I have managed to write a server script to return a pdf file from an API as below. What I want to know is how can I save the pdf output somewhere and then use as a attachment to an email I'm sending from my app using sendgrid?

Image

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Appery.io instructions to generate a pdf from the front end

Hi,

You can save files to Database
Then get this file when you send e-mail.

Aeneas McBurney
Posts: 0
Joined: Mon Jun 16, 2014 7:49 am

Appery.io instructions to generate a pdf from the front end

Ok thanks but what is code to save to the database?

Ihor Didevych
Posts: 0
Joined: Wed Nov 19, 2014 7:55 pm

Appery.io instructions to generate a pdf from the front end

Hi Aeneas,

You can use this document to write code in Server-Code script
http://devcenter.appery.io/documentat...

Aeneas McBurney
Posts: 0
Joined: Mon Jun 16, 2014 7:49 am

Appery.io instructions to generate a pdf from the front end

I have tried using this code

var url = "http://api.page2images.com/directlink?;

var responseBody = {};

var requestBody = {
"convert": "http://www.stabletrack.net/files/invo..."
};
var request = {
"headers": {
"Content-type": "application/x-www-form-urlencoded\r\n"
},
"data": requestBody
};

var XHRResponse = XHR2.send("GET", url);
response.success(XHRResponse.body, "application/text");

var res = XHRResponse.body

url="https://api.appery.io/rest/1/db/files"

var request = {
"headers": {
"X-Appery-Database-Id": "xxxxx",
"X-Appery-Master-Key": "xxxxxxx"
},
"data": res
};

var XHRResponse = XHR2.send("POST", url, request);

response.success(XHRResponse.body, "text/plain");
console.dir(XHRResponse);

However I always get error saying unable to consume datatype. This is because the data returned from XHR cannot be a binary type to upload into the file database.

How do I return the proper data type from a httpRequest in server code so I can upload into database?

I also want to know how to reference "http://www.stabletrack.net/files/invo..." as a relative reference not absolute. So without http://www.stabletrack.net/

Thanks,
Aeneas

Ihor Didevych
Posts: 0
Joined: Wed Nov 19, 2014 7:55 pm

Appery.io instructions to generate a pdf from the front end

We are working on it.
I will let you know when have more information from developers team.

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Appery.io instructions to generate a pdf from the front end

Hello,

1) File type can be binary, or you should be able to save any images or other files format. Your problem in parameters.

2) Unfortunately, writing and debugging custom script is outside the support's scope.
You can use this document to write code in Server-Code script
http://devcenter.appery.io/documentat...

Aeneas McBurney
Posts: 0
Joined: Mon Jun 16, 2014 7:49 am

Appery.io instructions to generate a pdf from the front end

Where is option to make file type binary from xhr2? Also what is the problem with my parameters?

Return to “Issues”