From c8301490cbf5a7950b3a6961e2b5a404e63a6925 Mon Sep 17 00:00:00 2001 From: kev-le Date: Fri, 1 Mar 2024 17:59:44 -0800 Subject: [PATCH] Url encode md5 string when requesting presigned url --- StudioClient/Photo.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/StudioClient/Photo.cs b/StudioClient/Photo.cs index ded5e95..8a3dcae 100644 --- a/StudioClient/Photo.cs +++ b/StudioClient/Photo.cs @@ -72,7 +72,7 @@ private async Task UploadPhoto(string photoPath, string modelName, long byte[] md5Hash = md5.ComputeHash(photoData); string md5Base64 = Convert.ToBase64String(md5Hash); - dynamic uploadObj = await GetUploadUrl(photo.id.Value, md5Base64); + dynamic uploadObj = await GetUploadUrl(photo.id.Value, System.Net.WebUtility.UrlEncode(md5Base64)); string presignedUrl = uploadObj.url.Value; using (RestClient httpClient = new RestClient()) @@ -81,8 +81,8 @@ private async Task UploadPhoto(string photoPath, string modelName, long RestRequest request = new RestRequest(presignedUrl, Method.Put); request.AddParameter("application/octet-stream", fileBytes, ParameterType.RequestBody); - request.AddHeader("Content-MD5", Convert.ToBase64String(MD5.Create().ComputeHash(fileBytes))); - if (modelName == "job") request.AddHeader("X-Amz-Tagging", "job=photo&api=true"); + request.AddHeader("Content-MD5", Convert.ToBase64String(md5.ComputeHash(fileBytes))); + if (modelName == "job") request.AddHeader("X-Amz-Tagging", "job=photo&api=true"); // Upload image via PUT request to presigned url RestResponse response = await httpClient.ExecuteAsync(request);