Skip to content

Commit

Permalink
Merge pull request #8 from skylab-tech/version-0.0.9
Browse files Browse the repository at this point in the history
Url encode md5 string when requesting presigned url
  • Loading branch information
kev-le authored Mar 2, 2024
2 parents 5626de4 + 5129213 commit 089d177
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions StudioClient/Photo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private async Task<dynamic> 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())
Expand All @@ -129,7 +129,8 @@ private async Task<dynamic> 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)));
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
Expand Down

0 comments on commit 089d177

Please sign in to comment.