Sign In Register

How can we help you today?

Start a new topic

Retrieving fields sent with Unity WWWForm

I've been following the example here to upload files with Unity:


https://support.gamesparks.net/support/discussions/topics/1000050374


In the example, custom post data is added to the request when the file is uploaded:

form.AddField("somefield", "somedata");

 How can I retrieve this data on the cloud code side?


Does this mean the POST data added to the form with AddField is not accessible through cloud code?

Hi Benjamin,


If you add the following to your UploadCompleteMessage you will be able to keep a custom runtime collection with all of the details of the files uploaded by users. This would include any data that you set to the "uploadData" of the GetUploadUrlRequest.


   

//in your UploadCompleteMessage Cloud Code

var dataToGrab = Spark.getData().uploadData;

var uploadedFiles = Spark.runtimeCollection("uploadedFiles");

var success = uploadedFiles.insert({"uploadedData":dataToGrab})


//example request

{
 "@class": ".GetUploadUrlRequest",
 "uploadData": 
  {"test":"value"}
}

//example of document in custom collection after successful upload 

{
 "_id": {
  "$oid": "58053fc538c31604dd9a69c7"
 },
 "uploadedData": {
  "fileName": "eb7a5ecf50ce40d59132877706c46efe-2016-09-07_17h13_43.jpg",
  "uploadId": "eb7a5ecf50ce40d59132877706c46efe",
  "test": "value",
  "fileSize": 689094,
  "origFileName": "2016-09-07_17h13_43.jpg",
  "playerId": "5800f32a8b146964b4b4038f"
 }
}

  

You will then be able to query this as you would a normal collection. If you have any further questions just let me know.


Thanks,

Liam 



Login to post a comment