question

Juan M S Paixao avatar image
Juan M S Paixao asked

Need help to understand how to upload a Json file on Entity File

I'm trying everything I can and searched on google and playfab forums but could not find an answer

This is the code on the documentation, I need to upload a Dictionary <string,object> instead of a string :(

Can someone help me where am I missing? I already read multiple times de playfab entity documentation and I'm already using the Entity Object to save player data, but I need to save stage data on a file (because bigger file size). Thank you!

Player Dataentities
capturar.png (43.7 KiB)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Citrus Yan avatar image
Citrus Yan answered

Here is what I did: serialize Dictionary <string,object> into a JSON string, encode it into a byte array (byte[]) and upload it as Entity File to PlayFab:

void OnInitFileUpload(PlayFab.DataModels.InitiateFileUploadsResponse response)
{
//define a sample Dictionary<string, object> varaible
        Dictionary<string, object> entityFile = new Dictionary<string, object>()
        {
            {"Health", 100 },
            {"Mana", 10000}


        };
       //Serialize it to JSON and convert to byte[]
        var payload = Encoding.UTF8.GetBytes(PlayFab.PluginManager.GetPlugin<ISerializerPlugin>(PluginContract.PlayFab_Serializer).SerializeObject(entityFile));


        GlobalFileLock += 1; // Start SimplePutCall
//upload
        PlayFabHttp.SimplePutCall(response.UploadDetails[0].UploadUrl,
            payload,
            FinalizeUpload,
            error => { GlobalFileLock -= 1; Debug.Log(error); }
        );
        GlobalFileLock -= 1; // Finish InitiateFileUploads
}


<br>

The content of the file will be the JSON representation of Dictionary <string,object>:

{"Health":100,"Mana":10000}
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.