Page 2 of 3

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

Posted: Mon Jan 19, 2015 6:48 pm
by Aeneas McBurney

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?


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

Posted: Tue Jan 20, 2015 1:08 am
by Aeneas McBurney

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


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

Posted: Tue Jan 20, 2015 2:41 pm
by Alena Prykhodko

Hi,

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


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

Posted: Tue Jan 20, 2015 5:14 pm
by Aeneas McBurney

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


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

Posted: Wed Jan 21, 2015 11:29 am
by Ihor Didevych

Hi Aeneas,

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


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

Posted: Wed Jan 21, 2015 4:38 pm
by Aeneas McBurney

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


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

Posted: Thu Jan 22, 2015 5:25 pm
by Aeneas McBurney

Any help with this?


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

Posted: Thu Jan 22, 2015 5:46 pm
by Ihor Didevych

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


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

Posted: Fri Jan 23, 2015 1:04 pm
by Alena Prykhodko

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...


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

Posted: Fri Jan 23, 2015 4:22 pm
by Aeneas McBurney

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