diff --git a/Thirdweb.Tests/Thirdweb.Storage.Tests.cs b/Thirdweb.Tests/Thirdweb.Storage.Tests.cs index 7af57af..2d88c83 100644 --- a/Thirdweb.Tests/Thirdweb.Storage.Tests.cs +++ b/Thirdweb.Tests/Thirdweb.Storage.Tests.cs @@ -46,6 +46,15 @@ public async Task DownloadTest_ThirdwebIPFS() Assert.NotNull(res); } + [Fact] + public async Task DownloadTest_Bytes() + { + var client = ThirdwebClient.Create(secretKey: _secretKey); + var res = await ThirdwebStorage.Download(client, "https://1.rpc.thirdweb.com/providers"); + Assert.NotNull(res); + Assert.NotEmpty(res); + } + [Fact] public async Task DownloadTest_400() { diff --git a/Thirdweb/Thirdweb.Storage/ThirdwebStorage.cs b/Thirdweb/Thirdweb.Storage/ThirdwebStorage.cs index a801ae2..54c6052 100644 --- a/Thirdweb/Thirdweb.Storage/ThirdwebStorage.cs +++ b/Thirdweb/Thirdweb.Storage/ThirdwebStorage.cs @@ -24,9 +24,19 @@ public static async Task Download(ThirdwebClient client, string uri, int? throw new Exception($"Failed to download {uri}: {response.StatusCode} | {await response.Content.ReadAsStringAsync()}"); } - var content = await response.Content.ReadAsStringAsync(); - - return typeof(T) == typeof(string) ? (T)(object)content : JsonConvert.DeserializeObject(content); + if (typeof(T) == typeof(byte[])) + { + return (T)(object)await response.Content.ReadAsByteArrayAsync(); + } + else if (typeof(T) == typeof(string)) + { + return (T)(object)await response.Content.ReadAsStringAsync(); + } + else + { + var content = await response.Content.ReadAsByteArrayAsync(); + return JsonConvert.DeserializeObject(System.Text.Encoding.UTF8.GetString(content)); + } } public static async Task Upload(ThirdwebClient client, string path)