diff --git a/StudioClient/Photo.cs b/StudioClient/Photo.cs index 19d3176..e1acd0c 100644 --- a/StudioClient/Photo.cs +++ b/StudioClient/Photo.cs @@ -1,3 +1,4 @@ +using System; using System.Drawing.Imaging; using System.Security.Cryptography; using NetVips; @@ -98,9 +99,35 @@ public async Task GetUploadUrl(long photoId, string md5 = "", bool useC /// The path to the photo file. /// The ID of the job associated with the photo. /// A dynamic object representing the uploaded photo. - public async Task UploadJobPhoto(string photoPath, long jobId) + public async Task UploadJobPhoto(string photoPath, long jobId) { - return await UploadPhoto(photoPath, "job", jobId); + const int maxRetries = 3; + int attempt = 0; + + while (attempt < maxRetries) + { + try + { + return await UploadPhoto(photoPath, "job", jobId); + } + catch (Exception ex) + { + attempt++; + + // If we've reached the max number of retries, rethrow the exception + if (attempt == maxRetries) + { + throw new Exception($"Failed to upload photo after {maxRetries} attempts", ex); + } + + // Wait for 2 seconds before retrying + await Task.Delay(2000); + } + } + + // This will never be reached due to the return in the loop, + // but we include it to satisfy the method's return type. + return null; } /// @@ -109,9 +136,35 @@ public async Task UploadJobPhoto(string photoPath, long jobId) /// The path to the photo file. /// The ID of the profile associated with the photo. /// A dynamic object representing the uploaded photo. - public async Task UploadProfilePhoto(string photoPath, long profileId) + public async Task UploadProfilePhoto(string photoPath, long profileId) { - return await UploadPhoto(photoPath, "profile", profileId); + const int maxRetries = 3; + int attempt = 0; + + while (attempt < maxRetries) + { + try + { + return await UploadPhoto(photoPath, "profile", profileId); + } + catch (Exception ex) + { + attempt++; + + // If we've reached the max number of retries, rethrow the exception + if (attempt == maxRetries) + { + throw new Exception($"Failed to upload photo after {maxRetries} attempts", ex); + } + + // Wait for 2 seconds before retrying + await Task.Delay(2000); + } + } + + // This will never be reached due to the return in the loop, + // but we include it to satisfy the method's return type. + return null; } ///