From a62a9ffc5b6d5c907c7160b19499e4a2bd4cff71 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Wed, 23 Jul 2025 17:00:54 -0600 Subject: [PATCH] Use HttpClient in synchronous mode --- Source/LibationFileManager/PictureStorage.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Source/LibationFileManager/PictureStorage.cs b/Source/LibationFileManager/PictureStorage.cs index d07bcf79..582d55d8 100644 --- a/Source/LibationFileManager/PictureStorage.cs +++ b/Source/LibationFileManager/PictureStorage.cs @@ -133,7 +133,16 @@ namespace LibationFileManager try { var sizeStr = def.Size == PictureSize.Native ? "" : $"._SL{(int)def.Size}_"; - var bytes = imageDownloadClient.GetByteArrayAsync("ht" + $"tps://images-na.ssl-images-amazon.com/images/I/{def.PictureId}{sizeStr}.jpg", cancellationToken).Result; + + using var requestMessage = new HttpRequestMessage(HttpMethod.Get, "ht" + $"tps://images-na.ssl-images-amazon.com/images/I/{def.PictureId}{sizeStr}.jpg"); + using var response = imageDownloadClient.Send(requestMessage, HttpCompletionOption.ResponseHeadersRead, cancellationToken).EnsureSuccessStatusCode(); + + if (response.Content.Headers.ContentLength is not long size) + return GetDefaultImage(def.Size); + + var bytes = new byte[size]; + using var respStream = response.Content.ReadAsStream(cancellationToken); + respStream.ReadExactly(bytes); // save image file. make sure to not save default image var path = getPath(def);