Skip to content

Commit

Permalink
Fix resized image not uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
kev-le committed Sep 26, 2024
1 parent 4ccb78c commit aae88c6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions StudioClient/Photo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,22 @@ private async Task<dynamic> 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));
string presignedUrl = uploadObj.url.Value;

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);
Expand Down

0 comments on commit aae88c6

Please sign in to comment.