Juan Pieterse
Posts: 0
Joined: Sat Apr 25, 2015 1:47 pm

File upload via Server Script

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!! :)

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

File upload via Server Script

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

Juan Pieterse
Posts: 0
Joined: Sat Apr 25, 2015 1:47 pm

File upload via Server Script

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

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

File upload via Server Script

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.

Juan Pieterse
Posts: 0
Joined: Sat Apr 25, 2015 1:47 pm

File upload via Server Script

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.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

File upload via Server Script

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

Matt6607699
Posts: 0
Joined: Sat Jan 25, 2014 7:18 am

File upload via Server Script

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

Return to “Issues”