99using System . Threading ;
1010using System . Threading . Tasks ;
1111using ManagedCode . Communication ;
12- using ManagedCode . Storage . Core . Helpers ;
1312using ManagedCode . Storage . Core . Models ;
14- using ManagedCode . Storage . Server ;
15- using Microsoft . Extensions . Configuration ;
1613
1714namespace ManagedCode . Storage . Client ;
1815
1916public class StorageClient : IStorageClient
2017{
2118 private readonly HttpClient _httpClient ;
22- private readonly IConfiguration _configuration ;
23-
24- public StorageClient ( HttpClient httpClient , IConfiguration configuration )
19+ private long _chunkSize ;
20+
21+ public StorageClient ( HttpClient httpClient )
2522 {
2623 _httpClient = httpClient ;
27- _configuration = configuration ;
2824 }
2925
26+ public long ChunkSize
27+ {
28+ get
29+ {
30+ if ( _chunkSize == null )
31+ {
32+ throw new NullReferenceException ( "ChunkSize doesn't set" ) ;
33+ }
34+ return _chunkSize ;
35+ }
36+ set
37+ {
38+ _chunkSize = value ;
39+ }
40+ }
41+
42+ public void SetChunkSize ( long size )
43+ {
44+ ChunkSize = size ;
45+ }
46+
3047 public async Task < Result < BlobMetadata > > UploadFile ( Stream stream , string apiUrl , string contentName , CancellationToken cancellationToken = default )
3148 {
3249 var streamContent = new StreamContent ( stream ) ;
@@ -135,10 +152,9 @@ public async Task<Result<uint>> UploadLargeFile(Stream file,
135152 Action < double > ? onProgressChanged ,
136153 CancellationToken cancellationToken = default )
137154 {
138- int bufferSize = Int32 . Parse ( _configuration . GetSection ( " ChunkSize" ) . Value ) ;
155+ long bufferSize = ChunkSize ;
139156 var buffer = new byte [ bufferSize ] ;
140157 int chunkIndex = 1 ;
141- uint fileCRC = 123214 ;
142158 var partOfProgress = file . Length / bufferSize ;
143159 var fileName = "file" + Guid . NewGuid ( ) ;
144160
@@ -157,7 +173,6 @@ public async Task<Result<uint>> UploadLargeFile(Stream file,
157173 formData . Add ( content , "File" , fileName ) ;
158174 formData . Add ( new StringContent ( chunkIndex . ToString ( ) ) , "Payload.ChunkIndex" ) ;
159175 formData . Add ( new StringContent ( bufferSize . ToString ( ) ) , "Payload.ChunkSize" ) ;
160- formData . Add ( new StringContent ( fileCRC . ToString ( ) ) , "Payload.FullCRC" ) ;
161176 await _httpClient . PostAsync ( uploadApiUrl , formData , cancellationToken ) ;
162177 }
163178 }
0 commit comments