Sign In Register

How can we help you today?

Start a new topic

Set custom parameters when uploading a file and then retrieve them

Hello!


I'm currently trying to upload a JSON file through C# code in Unity, and that it working great, but I also want to set some parameters, like who made the file, when it was created, difficulty, etc. Is there a way to do this? From the example I found before (lost the URL), you can use WWWForm() and then AddField. Could they be used somehow? I'm not very familiar with them either.


Thanks in advance!


Hi Hampus,


I would tend to agree with you on this one. I'll run this by the dev team and see if we can make any improvements here. For now using the UploadedCompleteMessage to create a custom runtime collection would be the best course of action. You'll be able to query this in events and even make changes to the data stored with the uploadable if required. You can use deleteUploadedFile to delete an uploaded file. If using a runtime collection to this would be a good point to remove that particular document.


Regards,

Liam

Hello


If I'm going to be honest, that seems to be some really bad designs and it just puts me off. There needs to be a way to easily get file info and the actual file that the player themselves didn't upload. And a way to "bulk get" a bunch of files seems to be missing, or is overly complicated to accomplish, which would also be an important part in this.

Hi Hampus,


Apologies for the delayed response. Currently this would be the best way to achieve what you are trying to do. You'll need to store the uploadIds for a player as the files are uploaded. You could store in them a collection as detailed above or on the player in their scriptData.


Regards,

Liam

Hello


I've I understood correctly, I can only get the data from a file that I uploaded in the same session, but I want to get it from any file that I've uploaded. And even judging by the code you've just posted, it seems very convoluted to just get a JSON field.

Hi Hampus,


You can add the following to your UploadCompleteMessage to log the file information to a custom runtime collection.


var dataToGrab = Spark.getData().uploadData;

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

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

 

Then when sending the GetUploadedRequest you can query this collection for the uploadId thats been passed in, set the file data to the request scriptData, get it in the GetUploadedResponse and set it to this responses scriptData. Dos this sound like it would work for you ?


Thanks,

Liam


So I created a GSRequestData for the uploadData in my Upload function and that seems to work. My fields appear in the NoSQL explorer. But then how do I access these fields when using GetUploadedRequest? I've been testing all sorts of things that I can access from the response but nothing contains my field, by the looks of it.

Hi Hampus,


Yes you are correct, you can add custom scriptData with an uploadedFile by attatching the "uploadData" attribute. This is a Array of JSON documents that are attatched the the GetUploadURLRequest. 


Please see here for more information.


-Pádraig

Login to post a comment