Page 1 of 1

File upload via Server Script

Posted: Sun Jun 26, 2016 10:10 pm
by Juan Pieterse

I have created some custom server script that populates collection rows with data/does queries etc. It all works great thanks to your documentation and exellent pointer from THE Max Katz and others from appery.io

I do have a question on uploading files.
For security reasons etc. I keep my database keys etc stored SERVER side in the code. I would like to adapt one of my server scripts to handle files. I have added a column (of tipe "file") to a collection. How would I send a file to my REST service?

I imagine the file needs to be encoded to a base64 string to the service (?)
I have looked at your tutorials and the related posts all seem to use master keys etc for the database. In short, I'd like to see some example code of a server script handling a submitted file. (in my case it would be an image.)

Thanks!! :)


File upload via Server Script

Posted: Mon Jun 27, 2016 4:42 pm
by Serhii Kulibaba

Hello Juan,

Please use a simple XMLHttpRequest on the Server Code: https://devcenter.appery.io/documenta...

To the Appery.io database: https://devcenter.appery.io/documenta...


File upload via Server Script

Posted: Tue Jun 28, 2016 9:02 am
by Juan Pieterse

It does not work.

Currently my app authenticates through Facebook ONLY. I have a "usersettings" collection which I update and 'pull' bits of data in the FB graph api from. This works great.

Looking at the documentation for the Files Collection it seem that one of the required parameters is a user token.
I'll create a 'FilesUser' in the users table and then I intend to do the following.

Have a Server script 'log' in the "FilesUser'-user, and retrieve the access token.
Then use the access token top upload a file to the Files collection.
But there is NO documentation on how to upload files via server code. PLEASE PLEASE help!!


File upload via Server Script

Posted: Wed Jun 29, 2016 2:58 pm
by Serhii Kulibaba

In that case it is better to upload files from the application itself. Because it is impossible to use Facebook Graph API in Server Code.


File upload via Server Script

Posted: Fri Jul 01, 2016 6:14 pm
by Juan Pieterse

Actually I do a lot of facebook graph stuff on the server code.
The app passes the facebook token to the server script, essentially as a parameter and graph api returns profile information:
// FBToken is a param sent from client
var FBMeUrl = "https://graph.facebook.com/me"; // REST API URL FB Graph
var XHRResponse = XHR2.send("GET", FBMeUrl, {
"parameters": {
"access_token": FBToken
}
});
var resBodyObj = JSON.parse(XHRResponse.body);
......
.....

I do a lot of user validation etc in my Server code. It works 100%
Essentially, I'd like to UPLOAD a file, but upload it through my own server code.
So, in summary how do I go about sending a file to a REST service?
And in the server code of the above REST service, how do I go about storing that file in the Files collection.


File upload via Server Script

Posted: Mon Jul 04, 2016 7:58 am
by Serhii Kulibaba

You are able to use simple XMLHttpRequest https://devcenter.appery.io/documenta...
to send any request you want, but Server Code doesn't have a FormData object for uploading files


File upload via Server Script

Posted: Thu Dec 08, 2016 5:34 am
by Matt6607699

So files/pictures can only be uploaded to the db by exposing the master key using the app plugin?