From aae88c642d24eaa852270d5f316a096c79290204 Mon Sep 17 00:00:00 2001 From: Kevin Le Date: Thu, 26 Sep 2024 14:46:53 -0700 Subject: [PATCH] Fix resized image not uploading --- StudioClient/Photo.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/StudioClient/Photo.cs b/StudioClient/Photo.cs index 66ba330..510d926 100644 --- a/StudioClient/Photo.cs +++ b/StudioClient/Photo.cs @@ -202,12 +202,15 @@ private async Task UploadPhoto(string photoPath, string modelName, long PhotoMetadata photoMetadata = GetImageMetadata(photoData); Image image = Image.NewFromBuffer(photoData); - Image modifiedImage = ResizeImage(image, photoMetadata); - + string format = ".jpg"; + if (photoMetadata.Format != null && photoMetadata.Format.Equals(ImageFormat.Png)) { + format = ".png"; + } + byte[] fileBytes = modifiedImage.WriteToBuffer($".{format}[Q=98]"); var md5 = MD5.Create(); - byte[] md5Hash = md5.ComputeHash(photoData); + byte[] md5Hash = md5.ComputeHash(fileBytes); string md5Base64 = Convert.ToBase64String(md5Hash); dynamic uploadObj = await GetUploadUrl(photo.id.Value, System.Net.WebUtility.UrlEncode(md5Base64)); @@ -215,7 +218,6 @@ private async Task UploadPhoto(string photoPath, string modelName, long using (RestClient httpClient = new RestClient()) { - byte[] fileBytes = File.ReadAllBytes(photoPath); RestRequest request = new RestRequest(presignedUrl, Method.Put); request.AddParameter("application/octet-stream", fileBytes, ParameterType.RequestBody);