Page 1 of 1

How can I generate content for a file in server code and then create a file in the Files collection with that content?

Posted: Sat Apr 26, 2014 10:18 pm
by Al Hooton

I have server code written that generates content for a small file into a variable. I don't want to send this as a file to the client, rather, I want to create a file in the Files collection with this content. All the examples I'm finding for working with the Files collection assume this is being driven from the client, but I want to do it from server code.


How can I generate content for a file in server code and then create a file in the Files collection with that content?

Posted: Sun Apr 27, 2014 6:06 pm
by Illya Stepanov

Hi Al -

Sorry for the delay, we need to clarify this issue with our developers.
We'll update when we get more information.


How can I generate content for a file in server code and then create a file in the Files collection with that content?

Posted: Mon Apr 28, 2014 5:02 am
by Alena Prykhodko

You can use server code XHR and Upload files service to do what you want.

Please read documentation about uploading files:

http://docs.appery.io/documentation/b...

To understand how work with XHR see the following code:

pre
var requestBody = {

"status": "sent",

"payload": {
"message": "Hello World",
},

"filter": {
"deviceID": deviceID
}
};

var request = {

"headers": {

Code: Select all

 "X-Appery-Push-API-Key": pushApiKey, 
 "Content-Type": "application/json" 

},

"body": JSON.stringify(requestBody)

};

var XHRResponse = XHR.send("POST", "https://api.appery.io/rest/push/msg", request);
/pre


How can I generate content for a file in server code and then create a file in the Files collection with that content?

Posted: Tue Apr 29, 2014 1:01 am
by Al Hooton

Ah, OK, I see -- thanks!