Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Url encode md5 string when requesting presigned url #8

Merged
merged 2 commits into from
Mar 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading