question

Kim Strasser avatar image
Kim Strasser asked

How can I upload a text file to Title Player Account Files?

https://docs.microsoft.com/en-us/gaming/playfab/features/data/entities/quickstart

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

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

void FinalizeUpload(byte[] data)
{
        GlobalFileLock += 1; // Start FinalizeFileUploads
        var request = new PlayFab.DataModels.FinalizeFileUploadsRequest
        {
            Entity = new PlayFab.DataModels.EntityKey { Id = entityId, Type = entityType },
            FileNames = new List<string> { ActiveUploadFileName },
        };
        PlayFabDataAPI.FinalizeFileUploads(request, OnUploadSuccess, OnSharedFailure);
        GlobalFileLock -= 1; // Finish SimplePutCall
}

I don't know how to upload a text file. Is "var payload" the text file that I want to upload?

What exactly is (byte[] data)? Is (byte[] data) the same as "var payload"?

For example, can I use FinalizeUpload(byte[] data) like this to upload a text file?

string assetPath = "/Users/myname/TESTFOLDER/MyFile.txt";
byte[] payload = File.ReadAllBytes(assetPath);
//call a PUT method and upload payload
FinalizeUpload(payload);
Account Management
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

·
Seth Du avatar image
Seth Du answered

I believe there is confusion on the documentation because in the FinalizeUpload section, the argument data (which is byte[]) is never used. Please simply ignore it.

To finalize the upload. Please refer to the documentation https://docs.microsoft.com/en-us/rest/api/playfab/data/file/finalizefileuploads?view=playfab-rest: The only properties that requires are entity keys and the filenames of your uploaded files.

The process will first call InitiateFileUploads to retrieve an upload URL, then upload it. When it is done, call FinalizeUpload API.

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.