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