question

frankmm8080 avatar image
frankmm8080 asked

Unity entity files error when i'm click button and upload file to playfab. Error: The resource Profile/Files/ was not valid. Error: Path must contain a value

I got an error like this: The resource Profile/Files/ was not valid. Error: Path must contain a value

when I click the upload button in my unity. I followed the Entity Files guide here: https://learn.microsoft.com/en-us/gaming/playfab/features/entities/entity-files

I'm still a beginner in playfab, and I created a new project in unity, below is my script for uploading: #if !DISABLE_PLAYFABENTITY_API && !DISABLE_PLAYFABCLIENT_API

 using PlayFab;
 using PlayFab.Internal;
 using System;
 using System.Collections.Generic;
 using System.Text;
 using UnityEngine;
    
 public class RegisterManager : MonoBehaviour
 {
     public string entityId; // Id representing the logged in player
     public string entityType; // entityType representing the logged in player
     private readonly Dictionary<string, string> _entityFileJson = new Dictionary<string, string>();
     public string ActiveUploadFileName;
     public string NewFileName;
     public int GlobalFileLock = 0; // Kind of cheap and simple way to handle this kind of lock
    
     private void Start()
     {
         Login();
     }
    
     void OnSharedFailure(PlayFabError error)
     {
         Debug.LogError(error.GenerateErrorReport());
         Debug.Log("FAILED = " + error);
         GlobalFileLock -= 1;
     }
    
     void Login()
     {
         var request = new PlayFab.ClientModels.LoginWithCustomIDRequest
         {
             CustomId = SystemInfo.deviceUniqueIdentifier,
             CreateAccount = true,
         };
         PlayFabClientAPI.LoginWithCustomID(request, OnLogin, OnSharedFailure);
     }
    
     void OnLogin(PlayFab.ClientModels.LoginResult result)
     {
         entityId = result.EntityToken.Entity.Id;
         // The expected entity type is title_player_account.
         entityType = result.EntityToken.Entity.Type;
         Debug.Log("create = " + result);
     }
    
     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 OnInitFailed(PlayFabError error)
     {
         if (error.Error == PlayFabErrorCode.EntityFileOperationPending)
         {
             // This is an error you should handle when calling InitiateFileUploads, but your resolution path may vary
             GlobalFileLock += 1; // Start AbortFileUploads
             var request = new PlayFab.DataModels.AbortFileUploadsRequest
             {
                 Entity = new PlayFab.DataModels.EntityKey { Id = entityId, Type = entityType },
                 FileNames = new List<string> { ActiveUploadFileName },
             };
             PlayFabDataAPI.AbortFileUploads(request, (result) => { GlobalFileLock -= 1; UploadFile(ActiveUploadFileName); }, OnSharedFailure); GlobalFileLock -= 1; // Finish AbortFileUploads
             GlobalFileLock -= 1; // Failed InitiateFileUploads
         }
         else
             OnSharedFailure(error);
     }
    
     void OnInitFileUpload(PlayFab.DataModels.InitiateFileUploadsResponse response)
     {
         string payloadStr;
         if (!_entityFileJson.TryGetValue(ActiveUploadFileName, out payloadStr))
             payloadStr = "{}";
         var payload = Encoding.UTF8.GetBytes(payloadStr);
    
         GlobalFileLock += 1; // Start SimplePutCall
         PlayFabHttp.SimplePutCall(response.UploadDetails[0].UploadUrl,
             payload,
             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
     }
 }
 #endif
Player DataTitle Dataentities
1 comment
10 |1200

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

Infer Wang avatar image Infer Wang commented ·

Could you please show me the entire error log, is the unity returns the error or the playfab sdk returns it?

0 Likes 0 ·

0 Answers

·

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.