question

Evgenia Almpanaki avatar image
Evgenia Almpanaki asked

Can I upload/download zip files using Entity Files?

I'm trying to upload/download a zip file using PlayFab, but I can't get back the original file. Instead I get a 1KB file that cannot be processed.

I used the entity files code from the documentation and at the end of downloading I used this to write it to a file.

WWW www = new WWW(fileData.DownloadUrl);
File.WriteAllBytes(Application.dataPath + "\\zipfile.zip", www.bytes);


// I also tried using UnityWebRequest. No difference.

Any ideas about what's wrong, or if what I want to do is even possible?

Thanks in advance!

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

·
Gosen Gao avatar image
Gosen Gao answered

Code below should work. I got it form the same document you mentioned, but some changes have been made. Would you please try it again?

    void GetActualFile(PlayFab.DataModels.GetFileMetadata fileData)
    {
        GlobalFileLock += 1; // Start Each SimpleGetCall
        PlayFabHttp.SimpleGetCall(fileData.DownloadUrl,
            result => {
                File.WriteAllBytes("C:\\datapath\\Test.zip", result);
                GlobalFileLock -= 1;
            }, // Finish Each SimpleGetCall
            error => {
                Debug.Log(error);
            }
        );
    }
3 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.

Evgenia Almpanaki avatar image Evgenia Almpanaki commented ·

Thank you for your reply.

I tried your suggestion, and I still can't get back the original file.

I think the problem is with uploading, because the file is very small even when I see on my PlayFab account.

0 Likes 0 ·
Gosen Gao avatar image Gosen Gao Evgenia Almpanaki commented ·

Have you checked the Checksum value when using the API to load/upload files? Is it the same?

Have you tried downloading the file from Game Manager? Is the resulting file the original?

If the problem is on the upload. Would you please try this code? I have already tested it and it works.

    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:\\datapath\\Test.zip");

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

<br>
0 Likes 0 ·
Evgenia Almpanaki avatar image Evgenia Almpanaki Gosen Gao commented ·

Thank you so much! This code worked. Have a nice day!

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.