Sign In Register

How can we help you today?

Start a new topic
Answered

GetUploadUrlRequest: uploadData

 Hi,


When sending a GetUploadUrlRequest you can pass an uploadData parameter (API Reference). The description says: "Optional meta data which is stored against the player’s uploaded content"

How / where is this data stored and how can you access it?

Thanks in advance,


Jannis


Best Answer

Hi Jannis,


The uploaded file details are currently stored in a system collection that is not exposed to users. You can however build a custom runtime collection to keep a record of these files yourself. You can do this by placing the the following code in Cloud Code>User>UploadCompletedMessage.


 

//grab the uploaded files details from the message
var dataToGrab = Spark.getData().uploadData;

//load our collection
var uploadedFiles = Spark.runtimeCollection("uploadedFiles");

//insert the data into our custom runtime collection
var success = uploadedFiles.insert({"uploadedData":dataToGrab})

 

With this you will end up with a mirrored collection containing a document each uploaded file.

 

//example document

{
 "_id": {
  "$oid": "57972176132aeb049cd83b1f"
 },
 "uploadedData": {
  "fileName": "585f354bcfd0436ab856fafbb2011bbb-2016-07-22_15h14_02.png",
  "uploadId": "585f354bcfd0436ab856fafbb2011bbb",
  "fileSize": 231352,
  "myKey": "myValue",
  "origFileName": "2016-07-22_15h14_02.png",
  "playerId": "578559cb92c95a70de956829"
 }
}

 

Just remember that if you use the "deleteUploadedFile" call from SparkFiles to remove an uploaded file, remember to remove the corresponding document from your custom collection while you are doing it, this will keep the collection up to date. If you have any further questions just let me know.


Thanks,

Liam

1 Comment

Answer

Hi Jannis,


The uploaded file details are currently stored in a system collection that is not exposed to users. You can however build a custom runtime collection to keep a record of these files yourself. You can do this by placing the the following code in Cloud Code>User>UploadCompletedMessage.


 

//grab the uploaded files details from the message
var dataToGrab = Spark.getData().uploadData;

//load our collection
var uploadedFiles = Spark.runtimeCollection("uploadedFiles");

//insert the data into our custom runtime collection
var success = uploadedFiles.insert({"uploadedData":dataToGrab})

 

With this you will end up with a mirrored collection containing a document each uploaded file.

 

//example document

{
 "_id": {
  "$oid": "57972176132aeb049cd83b1f"
 },
 "uploadedData": {
  "fileName": "585f354bcfd0436ab856fafbb2011bbb-2016-07-22_15h14_02.png",
  "uploadId": "585f354bcfd0436ab856fafbb2011bbb",
  "fileSize": 231352,
  "myKey": "myValue",
  "origFileName": "2016-07-22_15h14_02.png",
  "playerId": "578559cb92c95a70de956829"
 }
}

 

Just remember that if you use the "deleteUploadedFile" call from SparkFiles to remove an uploaded file, remember to remove the corresponding document from your custom collection while you are doing it, this will keep the collection up to date. If you have any further questions just let me know.


Thanks,

Liam

Login to post a comment