Hi there,
I am trying to upload a profile photo from the phone's gallery but I am getting "PlayerPhoto (pending file upload, cannot download)". Could you please help me with that?
Here is my code:
public void PickPhoto(int maxSize) { NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { Debug.Log("Image path: " + path); if (path != null) { // Create Texture from selected image Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize); // Assign the texture to the screen photo _profilePhoto.texture = texture; if (texture == null) { Debug.Log("Couldn't load texture from " + path); return; } } }, "Select a PNG image", "image/png"); Debug.Log("Permission result: " + permission); } public void UploadFile(string fileName) { if (GlobalFileLock != 0) throw new Exception("This example overly restricts file operations for safety. Careful consideration must be made when doing multiple file operations in parallel to avoid conflict."); ActiveUploadFileName = fileName; GlobalFileLock += 1; // Start InitiateFileUploads var request = new PlayFab.DataModels.InitiateFileUploadsRequest { Entity = new PlayFab.DataModels.EntityKey { Id = entityId, Type = entityType }, FileNames = new List<string> { ActiveUploadFileName }, }; PlayFabDataAPI.InitiateFileUploads(request, OnInitFileUpload, OnInitFailed); } void OnInitFileUpload(PlayFab.DataModels.InitiateFileUploadsResponse response) { Texture2D tex = (Texture2D)_profilePhoto.texture; tex.ReadPixels(new Rect(0, 0, _profilePhoto.texture.width, _profilePhoto.texture.height), 0, 0); tex.Apply(); byte[] bytes = tex.EncodeToPNG(); GlobalFileLock += 1; // Start SimplePutCall PlayFabHttp.SimplePutCall(response.UploadDetails[0].UploadUrl, bytes, FinalizeUpload, error => { Debug.Log(error); } ); GlobalFileLock -= 1; // Finish InitiateFileUploads } void FinalizeUpload(byte[] obj) { 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 } void OnUploadSuccess(PlayFab.DataModels.FinalizeFileUploadsResponse result) { Debug.Log("File upload success: " + ActiveUploadFileName); GlobalFileLock -= 1; // Finish FinalizeFileUploads }