question

Gerald Phillips avatar image
Gerald Phillips asked

Entity File Upload Help

Hello,

I've been banging my head around this for a couple days now. Any help would be much appreciated!

I currently use a binary formatter in Unity to serialize my player's game data class to a file and store it in Unity's persistent data path. I have followed and implemented the code in the Entity Files documentation.

I tried passing just the file name to the UploadFile function, but it just saves a blank file.

I tried passing the file path string to the UploadFile function, but it errors because of invalid characters in the path name. This doesn't make sense to me. The only thing I could think of is that the path has some spaces in some of the folder names, or it has something to do with the file type.

I tried creating a different serialization method using json and passing that file name to UploadFile, but I get a file doesn't exist type error.

I also looked into Entity Objects, but the documentation clearly states that all new titles should use Entity Files for more flexibility. My current json file is around 400 bytes, but I anticipate it growing a bit larger over time so I want to plan for that.

Is there another procedure that I am missing or doing incorrectly to get this to work?

Thanks!

entities
1 comment
10 |1200

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

Gerald Phillips avatar image Gerald Phillips commented ·

So think after really digging into the structure of the uploading procedure and searching deeper into other posts, I just have to change the OnItFileUpload to use my json string in the "payloadStr"? If that is the case, I am struggling to understand what this line means in the sample code:

if (!_entityFileJson.TryGetValue(ActiveUploadFileName, out payloadStr)) payloadStr = "{}";

0 Likes 0 ·

1 Answer

·
Gosen Gao avatar image
Gosen Gao answered

I am glad that you figure it out, you need to put the string to the payloadStr. The code you mentioned is trying to initialize the payloadStr, if it can get the Value from Dictionary _entityFileJson by key ActiveUploadFileName, then it will put the Value to payloadStr, otherwise, the payloadStr will be initialized as "{}". But if you want to read the local file and upload it to PlayFab, then you need to make some changes to the code.

Here is the code for your reference.

    void OnInitFileUpload(PlayFab.DataModels.InitiateFileUploadsResponse response)
    {
        //string payloadStr;
        //if (!_entityFileJson.TryGetValue(ActiveUploadFileName, out payloadStr))
        //    payloadStr = "{}";
        //var payload = Encoding.UTF8.GetBytes(payloadStr);

        var payload = File.ReadAllBytes("C:\\Users\\goseng\\Downloads\\Test.zip");

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

1 comment
10 |1200

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

anudeep avatar image anudeep commented ·

@Gosen Gao I followed the example as well but on line 13, I am getting an error which goes like:

error CS1503: Argument 3: cannot convert from 'method group' to 'Action<byte[]>'
am i missing something?

0 Likes 0 ·

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.