question

kevin-cg avatar image
kevin-cg asked

Cannot finalize file upload when overwriting a file

Hi there, I'm recently having problems uploading files with the Entity API while it seemed to work before.

I managed to replicate the behavior with a small piece of code:

byte[] bytesData = new byte[saveData.Length * sizeof(char)];
System.Buffer.BlockCopy(saveData.ToCharArray(), 0, bytesData, 0, bytesData.Length);


EntityKey entity = ((AndroidPlatform)Platform.GetInstance()).CurrentEntityKey;
var initiateFileUploadsRequest = new InitiateFileUploadsRequest
{
    Entity = entity,
    FileNames = new List<string> { "AllFiles.json" },
};
PlayFabEntityAPI.InitiateFileUploads(initiateFileUploadsRequest, (InitiateFileUploadsResponse response) =>
{
    Debug.Log("PlayFabTest: InitiateFileUploads success!");
    byte[] payload = bytesData;
    PlayFabHttp.SimplePutCall(response.UploadDetails[0].UploadUrl, payload, () =>
    {
        Debug.Log("PlayFabTest: SimplePutCall success!");
        var finalizeFileUploadsRequest = new FinalizeFileUploadsRequest
        {
            Entity = entity,
            FileNames = new List<string> { "AllFiles.json" },
        };
        PlayFabEntityAPI.FinalizeFileUploads(finalizeFileUploadsRequest, (FinalizeFileUploadsResponse finalizeFileUploadsResponse) =>
        {
            Debug.Log("PlayFabTest: Finalize success!");
        }, (PlayFabError err) =>
        {
            Debug.Log("PlayFabTest: Finalize failed! " + err);
        });


    }, (string err) =>
    {
        Debug.Log("PlayFabTest: SimplePutCall failed! " + err);
    });
}, (PlayFabError err) =>
{
    Debug.Log("PlayFabTest: InitiateFileUploads failed! " + err);
});

The problem I'm having is that it seems I cannot finalize the upload of a file, when a file with the same name already exists. This wasn't an issue before and only started occurring recently. When I make sure the file doesn't already exist this is logged:

PlayFabTest: InitiateFileUploads success!
PlayFabTest: SimplePutCall success!
PlayFabTest: Finalize success!

When the file already exists I get this:

PlayFabTest: InitiateFileUploads success!
PlayFabTest: SimplePutCall success!
PlayFabTest: Finalize failed! /File/FinalizeFileUploads PlayFabError(FileNotFound, The file AllFiles.json was not found by the storage provider. It must finish being uploaded before finalize can be called., 400 BadRequest)

It's odd that I get a FileNotFound error, even though I just initiated uploading that file and successfully finished uploading it. Am I missing something?

apisentities
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

·
brendan avatar image
brendan answered

We haven't been able to reproduce this in our testing. Would it be possible for you to send us a repro sample that demonstrates this behavior?

4 comments
10 |1200

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

kevin-cg avatar image kevin-cg commented ·

Hi Brendan, thanks for your message.

It seems you need a relatively big amount of data, so that it isn't done uploading instantly. For us it worked with at least 300kb.

I have actually been able to fix the issue by fixing some problems in the PlayFab SDK for Unity. There is a problem in PlayFabWWW.cs and in PlayFabWebRequest.cs, the former is broken when an upload cannot be instantly finished, and the latter is broken when a download cannot be instantly finished.

These are my changes in PlayFabWWW.cs:

In PlayFabWebRequest.cs:119 a stream is read for all the data it contains so far, and a callback is executed. However it's possible that the stream does not contain all data yet and it's still being filled. In this case the callback will be executed with only partially received data and the rest is lost.

Let me know if you need any more info.

0 Likes 0 ·
brendan avatar image brendan ♦♦ kevin-cg commented ·

Thanks for the additional info. Can you please submit a pull request with your changes to our GitHub repo for the SDK?

0 Likes 0 ·
kevin-cg avatar image kevin-cg brendan ♦♦ commented ·

Hi Brendan. I'm not sure how to do this on GitHub, could you just pass this on to the SDK development team? Thanks.

0 Likes 0 ·
Show more comments

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.

Error rendering WebPanel (widgets/consolidation-widget.ftl): org.hibernate.hql.internal.ast.QuerySyntaxException: AvailableConsolidation is not mapped [from AvailableConsolidation up where up.node = :node]