@@ -4080,9 +4080,8 @@ public static void GetAllPlayerFiles(int playerId, Action<LootLockerPlayerFilesR
40804080 /// <param name="filePurpose">Purpose of the file, example: savefile/config</param>
40814081 /// <param name="isPublic">Should this file be viewable by other players?</param>
40824082 /// <param name="onComplete">onComplete Action for handling the response of type LootLockerPlayerFile</param>
4083- /// <param name="key">Optional key for upsert behavior. If a file with this key already exists, it will be updated.</param>
40844083 /// <param name="forPlayerWithUlid">Optional : Execute the request for the specified player. If not supplied, the default player will be used.</param>
4085- public static void UploadPlayerFile(string pathToFile, string filePurpose, bool isPublic, Action<LootLockerPlayerFile> onComplete, string key = null, string forPlayerWithUlid = null)
4084+ public static void UploadPlayerFile(string pathToFile, string filePurpose, bool isPublic, Action<LootLockerPlayerFile> onComplete, string forPlayerWithUlid = null)
40864085 {
40874086 if (!CheckInitialized(false, forPlayerWithUlid))
40884087 {
@@ -4096,11 +4095,6 @@ public static void UploadPlayerFile(string pathToFile, string filePurpose, bool
40964095 { "public", isPublic.ToString().ToLower() }
40974096 };
40984097
4099- if (!string.IsNullOrEmpty(key))
4100- {
4101- body.Add("key", key);
4102- }
4103-
41044098 var fileBytes = new byte[] { };
41054099 try
41064100 {
@@ -4130,7 +4124,7 @@ public static void UploadPlayerFile(string pathToFile, string filePurpose, bool
41304124 /// <param name="forPlayerWithUlid">Optional : Execute the request for the specified player. If not supplied, the default player will be used.</param>
41314125 public static void UploadPlayerFile(string pathToFile, string filePurpose, Action<LootLockerPlayerFile> onComplete, string forPlayerWithUlid = null)
41324126 {
4133- UploadPlayerFile(pathToFile, filePurpose, false, onComplete, null, forPlayerWithUlid);
4127+ UploadPlayerFile(pathToFile, filePurpose, false, onComplete, forPlayerWithUlid);
41344128 }
41354129
41364130 /// @ingroup PlayerFiles
@@ -4141,9 +4135,8 @@ public static void UploadPlayerFile(string pathToFile, string filePurpose, Actio
41414135 /// <param name="filePurpose">Purpose of the file, example: savefile/config</param>
41424136 /// <param name="isPublic">Should this file be viewable by other players?</param>
41434137 /// <param name="onComplete">onComplete Action for handling the response of type LootLockerPlayerFile</param>
4144- /// <param name="key">Optional key for upsert behavior. If a file with this key already exists, it will be updated.</param>
41454138 /// <param name="forPlayerWithUlid">Optional : Execute the request for the specified player. If not supplied, the default player will be used.</param>
4146- public static void UploadPlayerFile(FileStream fileStream, string filePurpose, bool isPublic, Action<LootLockerPlayerFile> onComplete, string key = null, string forPlayerWithUlid = null)
4139+ public static void UploadPlayerFile(FileStream fileStream, string filePurpose, bool isPublic, Action<LootLockerPlayerFile> onComplete, string forPlayerWithUlid = null)
41474140 {
41484141 if (!CheckInitialized(false, forPlayerWithUlid))
41494142 {
@@ -4157,11 +4150,6 @@ public static void UploadPlayerFile(FileStream fileStream, string filePurpose, b
41574150 { "public", isPublic.ToString().ToLower() }
41584151 };
41594152
4160- if (!string.IsNullOrEmpty(key))
4161- {
4162- body.Add("key", key);
4163- }
4164-
41654153 var fileBytes = new byte[fileStream.Length];
41664154 try
41674155 {
@@ -4187,11 +4175,10 @@ public static void UploadPlayerFile(FileStream fileStream, string filePurpose, b
41874175 /// <param name="fileStream">Filestream to upload</param>
41884176 /// <param name="filePurpose">Purpose of the file, example: savefile/config</param>
41894177 /// <param name="onComplete">onComplete Action for handling the response of type LootLockerPlayerFile</param>
4190- /// <param name="key">Optional key for upsert behavior. If a file with this key already exists, it will be updated.</param>
41914178 /// <param name="forPlayerWithUlid">Optional : Execute the request for the specified player. If not supplied, the default player will be used.</param>
4192- public static void UploadPlayerFile(FileStream fileStream, string filePurpose, Action<LootLockerPlayerFile> onComplete, string key = null, string forPlayerWithUlid = null)
4179+ public static void UploadPlayerFile(FileStream fileStream, string filePurpose, Action<LootLockerPlayerFile> onComplete, string forPlayerWithUlid = null)
41934180 {
4194- UploadPlayerFile(fileStream, filePurpose, false, onComplete, key, forPlayerWithUlid);
4181+ UploadPlayerFile(fileStream, filePurpose, isPublic: false, onComplete, forPlayerWithUlid: forPlayerWithUlid);
41954182 }
41964183
41974184 /// @ingroup PlayerFiles
@@ -4203,9 +4190,8 @@ public static void UploadPlayerFile(FileStream fileStream, string filePurpose, A
42034190 /// <param name="filePurpose">Purpose of the file, example: savefile/config</param>
42044191 /// <param name="isPublic">Should this file be viewable by other players?</param>
42054192 /// <param name="onComplete">onComplete Action for handling the response of type LootLockerPlayerFile</param>
4206- /// <param name="key">Optional key for upsert behavior. If a file with this key already exists, it will be updated.</param>
42074193 /// <param name="forPlayerWithUlid">Optional : Execute the request for the specified player. If not supplied, the default player will be used.</param>
4208- public static void UploadPlayerFile(byte[] fileBytes, string fileName, string filePurpose, bool isPublic, Action<LootLockerPlayerFile> onComplete, string key = null, string forPlayerWithUlid = null)
4194+ public static void UploadPlayerFile(byte[] fileBytes, string fileName, string filePurpose, bool isPublic, Action<LootLockerPlayerFile> onComplete, string forPlayerWithUlid = null)
42094195 {
42104196 if (!CheckInitialized(false, forPlayerWithUlid))
42114197 {
@@ -4219,11 +4205,181 @@ public static void UploadPlayerFile(byte[] fileBytes, string fileName, string fi
42194205 { "public", isPublic.ToString().ToLower() }
42204206 };
42214207
4222- if (!string.IsNullOrEmpty(key))
4208+ LootLockerServerRequest.UploadFile(forPlayerWithUlid, LootLockerEndPoints.uploadPlayerFile, fileBytes, Path.GetFileName(fileName), "multipart/form-data", body,
4209+ onComplete: (serverResponse) =>
4210+ {
4211+ LootLockerResponse.Deserialize(onComplete, serverResponse);
4212+ });
4213+ }
4214+
4215+ /// @ingroup PlayerFiles
4216+ /// <summary>
4217+ /// Upload a file using a byte array. Can be useful if you want to upload without storing anything on disk. The file will be owned by the currently active player.
4218+ /// </summary>
4219+ /// <param name="fileBytes">Byte array to upload</param>
4220+ /// <param name="fileName">Name of the file on LootLocker</param>
4221+ /// <param name="filePurpose">Purpose of the file, example: savefile/config</param>
4222+ /// <param name="onComplete">onComplete Action for handling the response of type LootLockerPlayerFile</param>
4223+ /// <param name="forPlayerWithUlid">Optional : Execute the request for the specified player. If not supplied, the default player will be used.</param>
4224+ public static void UploadPlayerFile(byte[] fileBytes, string fileName, string filePurpose, Action<LootLockerPlayerFile> onComplete, string forPlayerWithUlid = null)
4225+ {
4226+ UploadPlayerFile(fileBytes, fileName, filePurpose, isPublic: false, onComplete, forPlayerWithUlid: forPlayerWithUlid);
4227+ }
4228+
4229+ /// @ingroup PlayerFiles
4230+ ///////////////////////////////////////////////////////////////////////////////
4231+
4232+ // ================================================================
4233+ // UploadPlayerFileByKey — dedicated overloads for upsert-by-key
4234+ // ================================================================
4235+
4236+ /// @ingroup PlayerFiles
4237+ /// <summary>
4238+ /// Upload a file with the provided name and content, using a key for upsert behavior.
4239+ /// If a file with the given key already exists for this player, it will be updated.
4240+ /// </summary>
4241+ /// <param name="pathToFile">Path to the file, example: Application.persistentDataPath + "/" + fileName;</param>
4242+ /// <param name="filePurpose">Purpose of the file, example: savefile/config</param>
4243+ /// <param name="isPublic">Should this file be viewable by other players?</param>
4244+ /// <param name="key">Key for upsert behavior. If a file with this key already exists, it will be updated.</param>
4245+ /// <param name="onComplete">onComplete Action for handling the response of type LootLockerPlayerFile</param>
4246+ /// <param name="forPlayerWithUlid">Optional : Execute the request for the specified player. If not supplied, the default player will be used.</param>
4247+ public static void UploadPlayerFileByKey(string pathToFile, string filePurpose, bool isPublic, string key, Action<LootLockerPlayerFile> onComplete, string forPlayerWithUlid = null)
4248+ {
4249+ if (!CheckInitialized(false, forPlayerWithUlid))
4250+ {
4251+ onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerPlayerFile>(forPlayerWithUlid));
4252+ return;
4253+ }
4254+
4255+ var body = new Dictionary<string, string>()
4256+ {
4257+ { "purpose", filePurpose },
4258+ { "public", isPublic.ToString().ToLower() },
4259+ { "key", key }
4260+ };
4261+
4262+ var fileBytes = new byte[] { };
4263+ try
4264+ {
4265+ fileBytes = File.ReadAllBytes(pathToFile);
4266+ }
4267+ catch (Exception e)
4268+ {
4269+ LootLockerLogger.Log($"File error: {e.Message}", LootLockerLogger.LogLevel.Error);
4270+ return;
4271+ }
4272+
4273+ LootLockerServerRequest.UploadFile(forPlayerWithUlid, LootLockerEndPoints.uploadPlayerFile, fileBytes, Path.GetFileName(pathToFile), "multipart/form-data", body,
4274+ onComplete: (serverResponse) =>
4275+ {
4276+ LootLockerResponse.Deserialize(onComplete, serverResponse);
4277+ });
4278+ }
4279+
4280+ /// @ingroup PlayerFiles
4281+ /// <summary>
4282+ /// Upload a file with the provided name and content, using a key for upsert behavior.
4283+ /// If a file with the given key already exists for this player, it will be updated.
4284+ /// The file will not be viewable by other players.
4285+ /// </summary>
4286+ /// <param name="pathToFile">Path to the file, example: Application.persistentDataPath + "/" + fileName;</param>
4287+ /// <param name="filePurpose">Purpose of the file, example: savefile/config</param>
4288+ /// <param name="key">Key for upsert behavior. If a file with this key already exists, it will be updated.</param>
4289+ /// <param name="onComplete">onComplete Action for handling the response of type LootLockerPlayerFile</param>
4290+ /// <param name="forPlayerWithUlid">Optional : Execute the request for the specified player. If not supplied, the default player will be used.</param>
4291+ public static void UploadPlayerFileByKey(string pathToFile, string filePurpose, string key, Action<LootLockerPlayerFile> onComplete, string forPlayerWithUlid = null)
4292+ {
4293+ UploadPlayerFileByKey(pathToFile, filePurpose, isPublic: false, key, onComplete, forPlayerWithUlid: forPlayerWithUlid);
4294+ }
4295+
4296+ /// @ingroup PlayerFiles
4297+ /// <summary>
4298+ /// Upload a file using a Filestream, using a key for upsert behavior.
4299+ /// If a file with the given key already exists for this player, it will be updated.
4300+ /// </summary>
4301+ /// <param name="fileStream">Filestream to upload</param>
4302+ /// <param name="filePurpose">Purpose of the file, example: savefile/config</param>
4303+ /// <param name="isPublic">Should this file be viewable by other players?</param>
4304+ /// <param name="key">Key for upsert behavior. If a file with this key already exists, it will be updated.</param>
4305+ /// <param name="onComplete">onComplete Action for handling the response of type LootLockerPlayerFile</param>
4306+ /// <param name="forPlayerWithUlid">Optional : Execute the request for the specified player. If not supplied, the default player will be used.</param>
4307+ public static void UploadPlayerFileByKey(FileStream fileStream, string filePurpose, bool isPublic, string key, Action<LootLockerPlayerFile> onComplete, string forPlayerWithUlid = null)
4308+ {
4309+ if (!CheckInitialized(false, forPlayerWithUlid))
4310+ {
4311+ onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerPlayerFile>(forPlayerWithUlid));
4312+ return;
4313+ }
4314+
4315+ var body = new Dictionary<string, string>()
4316+ {
4317+ { "purpose", filePurpose },
4318+ { "public", isPublic.ToString().ToLower() },
4319+ { "key", key }
4320+ };
4321+
4322+ var fileBytes = new byte[fileStream.Length];
4323+ try
4324+ {
4325+ fileStream.Read(fileBytes, 0, Convert.ToInt32(fileStream.Length));
4326+ }
4327+ catch (Exception e)
42234328 {
4224- body.Add("key", key);
4329+ LootLockerLogger.Log($"File error: {e.Message}", LootLockerLogger.LogLevel.Error);
4330+ return;
42254331 }
42264332
4333+ LootLockerServerRequest.UploadFile(forPlayerWithUlid, LootLockerEndPoints.uploadPlayerFile, fileBytes, Path.GetFileName(fileStream.Name), "multipart/form-data", body,
4334+ onComplete: (serverResponse) =>
4335+ {
4336+ LootLockerResponse.Deserialize(onComplete, serverResponse);
4337+ });
4338+ }
4339+
4340+ /// @ingroup PlayerFiles
4341+ /// <summary>
4342+ /// Upload a file using a Filestream, using a key for upsert behavior.
4343+ /// If a file with the given key already exists for this player, it will be updated.
4344+ /// The file will not be viewable by other players.
4345+ /// </summary>
4346+ /// <param name="fileStream">Filestream to upload</param>
4347+ /// <param name="filePurpose">Purpose of the file, example: savefile/config</param>
4348+ /// <param name="key">Key for upsert behavior. If a file with this key already exists, it will be updated.</param>
4349+ /// <param name="onComplete">onComplete Action for handling the response of type LootLockerPlayerFile</param>
4350+ /// <param name="forPlayerWithUlid">Optional : Execute the request for the specified player. If not supplied, the default player will be used.</param>
4351+ public static void UploadPlayerFileByKey(FileStream fileStream, string filePurpose, string key, Action<LootLockerPlayerFile> onComplete, string forPlayerWithUlid = null)
4352+ {
4353+ UploadPlayerFileByKey(fileStream, filePurpose, isPublic: false, key, onComplete, forPlayerWithUlid: forPlayerWithUlid);
4354+ }
4355+
4356+ /// @ingroup PlayerFiles
4357+ /// <summary>
4358+ /// Upload a file using a byte array, using a key for upsert behavior.
4359+ /// If a file with the given key already exists for this player, it will be updated.
4360+ /// </summary>
4361+ /// <param name="fileBytes">Byte array to upload</param>
4362+ /// <param name="fileName">Name of the file on LootLocker</param>
4363+ /// <param name="filePurpose">Purpose of the file, example: savefile/config</param>
4364+ /// <param name="isPublic">Should this file be viewable by other players?</param>
4365+ /// <param name="key">Key for upsert behavior. If a file with this key already exists, it will be updated.</param>
4366+ /// <param name="onComplete">onComplete Action for handling the response of type LootLockerPlayerFile</param>
4367+ /// <param name="forPlayerWithUlid">Optional : Execute the request for the specified player. If not supplied, the default player will be used.</param>
4368+ public static void UploadPlayerFileByKey(byte[] fileBytes, string fileName, string filePurpose, bool isPublic, string key, Action<LootLockerPlayerFile> onComplete, string forPlayerWithUlid = null)
4369+ {
4370+ if (!CheckInitialized(false, forPlayerWithUlid))
4371+ {
4372+ onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerPlayerFile>(forPlayerWithUlid));
4373+ return;
4374+ }
4375+
4376+ var body = new Dictionary<string, string>()
4377+ {
4378+ { "purpose", filePurpose },
4379+ { "public", isPublic.ToString().ToLower() },
4380+ { "key", key }
4381+ };
4382+
42274383 LootLockerServerRequest.UploadFile(forPlayerWithUlid, LootLockerEndPoints.uploadPlayerFile, fileBytes, Path.GetFileName(fileName), "multipart/form-data", body,
42284384 onComplete: (serverResponse) =>
42294385 {
@@ -4233,16 +4389,19 @@ public static void UploadPlayerFile(byte[] fileBytes, string fileName, string fi
42334389
42344390 /// @ingroup PlayerFiles
42354391 /// <summary>
4236- /// Upload a file using a byte array. Can be useful if you want to upload without storing anything on disk. The file will be owned by the currently active player.
4392+ /// Upload a file using a byte array, using a key for upsert behavior.
4393+ /// If a file with the given key already exists for this player, it will be updated.
4394+ /// The file will not be viewable by other players.
42374395 /// </summary>
42384396 /// <param name="fileBytes">Byte array to upload</param>
42394397 /// <param name="fileName">Name of the file on LootLocker</param>
42404398 /// <param name="filePurpose">Purpose of the file, example: savefile/config</param>
4399+ /// <param name="key">Key for upsert behavior. If a file with this key already exists, it will be updated.</param>
42414400 /// <param name="onComplete">onComplete Action for handling the response of type LootLockerPlayerFile</param>
42424401 /// <param name="forPlayerWithUlid">Optional : Execute the request for the specified player. If not supplied, the default player will be used.</param>
4243- public static void UploadPlayerFile (byte[] fileBytes, string fileName, string filePurpose, Action<LootLockerPlayerFile> onComplete, string forPlayerWithUlid = null)
4402+ public static void UploadPlayerFileByKey (byte[] fileBytes, string fileName, string filePurpose, string key , Action<LootLockerPlayerFile> onComplete, string forPlayerWithUlid = null)
42444403 {
4245- UploadPlayerFile (fileBytes, fileName, filePurpose, false, onComplete, null, forPlayerWithUlid);
4404+ UploadPlayerFileByKey (fileBytes, fileName, filePurpose, isPublic: false, key, onComplete, forPlayerWithUlid: forPlayerWithUlid);
42464405 }
42474406
42484407 /// @ingroup PlayerFiles
0 commit comments