@@ -27,36 +27,39 @@ internal static class HttpClientProgress
27
27
}
28
28
}
29
29
30
- using var response = await client . SendAsync ( message , HttpCompletionOption . ResponseHeadersRead ) . ConfigureAwait ( false ) ;
31
- if ( ! response . IsSuccessStatusCode )
30
+ using ( var response = await client . SendAsync ( message , HttpCompletionOption . ResponseHeadersRead ) )
32
31
{
33
- var content = await response . Content . ReadAsStringAsync ( ) ;
34
- var errorResponse = JsonConvert . DeserializeObject < ErrorResponse > ( content ) ;
35
- var e = new SupabaseStorageException ( errorResponse ? . Message ?? content )
32
+ if ( ! response . IsSuccessStatusCode )
36
33
{
37
- Content = content ,
38
- Response = response ,
39
- StatusCode = errorResponse ? . StatusCode ?? ( int ) response . StatusCode
40
- } ;
34
+ var content = await response . Content . ReadAsStringAsync ( ) ;
35
+ var errorResponse = JsonConvert . DeserializeObject < ErrorResponse > ( content ) ;
36
+ var e = new SupabaseStorageException ( errorResponse ? . Message ?? content )
37
+ {
38
+ Content = content ,
39
+ Response = response ,
40
+ StatusCode = errorResponse ? . StatusCode ?? ( int ) response . StatusCode
41
+ } ;
41
42
42
- e . AddReason ( ) ;
43
- throw e ;
44
- }
43
+ e . AddReason ( ) ;
44
+ throw e ;
45
+ }
45
46
46
- var contentLength = response . Content . Headers . ContentLength ;
47
- using var download = await response . Content . ReadAsStreamAsync ( ) ;
48
-
49
- // no progress... no contentLength... very sad
50
- if ( progress is null || ! contentLength . HasValue )
51
- {
52
- await download . CopyToAsync ( destination ) ;
53
- return destination ;
47
+ var contentLength = response . Content . Headers . ContentLength ;
48
+ using ( var download = await response . Content . ReadAsStreamAsync ( ) )
49
+ {
50
+ // no progress... no contentLength... very sad
51
+ if ( progress is null || ! contentLength . HasValue )
52
+ {
53
+ await download . CopyToAsync ( destination ) ;
54
+ return destination ;
55
+ }
56
+
57
+ // Such progress and contentLength much reporting Wow!
58
+ var progressWrapper = new Progress < long > ( totalBytes => progress . Report ( GetProgressPercentage ( totalBytes , contentLength . Value ) ) ) ;
59
+ await download . CopyToAsync ( destination , 81920 , progressWrapper , cancellationToken ) ;
60
+ }
54
61
}
55
62
56
- // Such progress and contentLength much reporting Wow!
57
- var progressWrapper = new Progress < long > ( totalBytes => progress . Report ( GetProgressPercentage ( totalBytes , contentLength . Value ) ) ) ;
58
- await download . CopyToAsync ( destination , 81920 , progressWrapper , cancellationToken ) ;
59
-
60
63
float GetProgressPercentage ( float totalBytes , float currentBytes ) => ( totalBytes / currentBytes ) * 100f ;
61
64
62
65
return destination ;
0 commit comments