question

Takuya Nakajo avatar image
Takuya Nakajo asked

Unable to upload UGC files

I was able to attach an image using CreateDraftItem, but I cannot attach a file. To be exact, it completes to CreateUploadUrls, CreateDraftItem, and PublishDraftItem, but I cannot open the detail page from GameManager. Is the coding of the file upload incorrect? I also get an error when I try to upload and save the file manually on GameManager.

Code

private List<UgcFile> ugcFiles = new List<UgcFile>();


private void CreateUploadUrls()
{
    CreateUgcFileData();

    PlayFabEconomyAPI.CreateUploadUrls(new CreateUploadUrlsRequest
    {
        Files = new List<UploadInfo>
        {
            new UploadInfo { FileName = ugcFiles[0].FileName }
        }
    }, result =>
    {
        Debug.Log("CreateUploadUrls Success!");
        int i = 1;
        foreach (var url in result.UploadUrls)
        {
            Debug.Log($"-- Count {i} --");
            Debug.Log($"ID : {url.Id}");
            Debug.Log($"URL : {url.Url}");
            Debug.Log($"FileName : {url.FileName}");

            var file = ugcFiles.FirstOrDefault(x => x.FileName == url.FileName);
            file.Id = url.Id;
            file.Url = url.Url;

            UploadFile(file.Url, file.FilePath, file.ContentType);
            i++;
        }
    }, error =>
    {
        Debug.Log(error.GenerateErrorReport());
    });
}

private void CreateUgcFileData()
{
    string filePath = @"/Users/test/Downloads/ugc/hello-world.txt";
    ugcFiles = new List<UgcFile>()
    {
        new UgcFile{ FilePath = filePath, FileName = "hello-world.txt", ContentType = ContentType.File },
    };
}

private void UploadFile(string url, string filePath, ContentType contentType)
{
    try
    {
        using var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read);

        var request = (HttpWebRequest)WebRequest.Create(url);
        request.Method = "PUT";
        request.ContentType = contentType == ContentType.Image ? "image/jpeg" : "text/plain";
        request.ContentLength = stream.Length;
        request.Timeout = 1 * 60 * 1000;
        request.ReadWriteTimeout = 1 * 60 * 1000;
        request.Headers.Add("comp", "blob");
        request.Headers.Add("x-ms-blob-type", "blockblob");

        using var requestStream = request.GetRequestStream();
        stream.CopyTo(requestStream);

        var response = request.GetResponse();

        Debug.Log("File Upload Success!!");
    }
    catch (Exception e)
    {
        Debug.Log($"Error : {e.StackTrace}");
    }
}

private void CreateDraftItemWithFiles()
{
    PlayFabEconomyAPI.CreateDraftItem(new CreateDraftItemRequest
    {
        Item = new PlayFab.EconomyModels.CatalogItem
        {
            Title = new Dictionary<string, string>
            {
                ["NEUTRAL"] = "Special Skin"
            },
            StartDate = new DateTime(2021, 12, 1),
            Type = "ugc",
            ContentType = "skin",
            Tags = new List<string> { "animal" },
            DisplayVersion = "1.0",
            Description = new Dictionary<string, string>
            {
                ["NEUTRAL"] = "cute pengin skin"
            },
            EndDate = new DateTime(2022, 1, 31),
            Contents = new List<Content>
            {
                new Content
                {
                    // Use the value obtained by CreateUploadUrls
                    Id = "3e8ae186-a069-49e6-8e16-94b5d6802074",
                    Url = "https://pfcatalogcontent2.blob.core.windows.net/xxxxxxxxxxx"
                }
            },
        },
    }, result =>
    {
        Debug.Log("CreateDraftItem Success!");
        Debug.Log($"{result.Item.Title["NEUTRAL"]} : {result.Item.Id}");
    }, error =>
    {
        Debug.Log(error.GenerateErrorReport());
    });
}


public class UgcFile
{
    public string Id { get; set; }
    public string Url { get; set; }
    public string FilePath { get; set; }
    public string FileName { get; set; }
    public ContentType ContentType { get; set; }
}

public enum ContentType
{
    Image,
    File,
}

hello-world.txt

Hello World!

Before selection

After Selection

Environment

Unity SDK 2.116.211012

Unity 2021.1.11f1

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

I have tested your code and it works well. It seems that something went wrong with the Game Manager. Could you please send us a fiddler trace or detailed error message from network tab of browser development panel so that we can do some further research?

12 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.

Takuya Nakajo avatar image Takuya Nakajo commented ·

Thank you for your confirmation. Please let me know if there is any information missing in the attached image.

スクリーンショット-2021-12-27-173957-min.png

0 Likes 0 ·
Gosen Gao avatar image Gosen Gao Takuya Nakajo commented ·

May I know your title Id?

0 Likes 0 ·
Takuya Nakajo avatar image Takuya Nakajo Gosen Gao commented ·

Title ID is B2347.

0 Likes 0 ·
Show more comments
Takuya Nakajo avatar image Takuya Nakajo commented ·

I couldn't reply to any more trees, so I'll reply to another tree. Fiddler had a 30 day free trial, so I installed it. This is my first time using it, so if there is any other information you need, please let me know.

スクリーンショット-2021-12-30-163620-min.png

0 Likes 0 ·
Gosen Gao avatar image Gosen Gao Takuya Nakajo commented ·

Could you please export all related requests from clicking on that item to reporting errors, and send the export file to us? Please remove any sensitive info.

0 Likes 0 ·
Takuya Nakajo avatar image Takuya Nakajo Gosen Gao commented ·

The file size is large, so I uploaded it to another service. I think I took it from just before I clicked on the UGC item until the error occurred. If any information is missing, please contact me with your email address and I will add your user to my title so that you can access it.

https://xgf.nu/SCJW

Download key: 1675

0 Likes 0 ·
Show more comments
Takuya Nakajo avatar image Takuya Nakajo commented ·

I have checked, but the problem is still not resolved.

0 Likes 0 ·
Gosen Gao avatar image Gosen Gao Takuya Nakajo commented ·

This issue has been resolved. Please have a check and let me know if there is anything wrong.

0 Likes 0 ·
Takuya Nakajo avatar image Takuya Nakajo Gosen Gao commented ·

I checked and the problem has been resolved. Thank you for your support!

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.