1- using System ;
1+ using ManagedCode . Communication ;
2+ using ManagedCode . Storage . Core . Models ;
3+ using System ;
24using System . Collections . Generic ;
35using System . IO ;
46using System . Net ;
57using System . Net . Http ;
68using System . Net . Http . Json ;
79using System . Threading ;
810using System . Threading . Tasks ;
9- using ManagedCode . Communication ;
10- using ManagedCode . Storage . Core . Models ;
1111
1212namespace ManagedCode . Storage . Client ;
1313
@@ -191,78 +191,26 @@ public async Task<Result<uint>> UploadLargeFile(Stream file,
191191 return await mergeResult . Content . ReadFromJsonAsync < Result < uint > > ( cancellationToken : cancellationToken ) ;
192192 }
193193
194- public Task < Result < BlobMetadata > > UploadAsync ( Stream stream , CancellationToken cancellationToken = default )
195- {
196- throw new NotImplementedException ( ) ;
197- }
198-
199- public Task < Result < BlobMetadata > > UploadAsync ( byte [ ] data , CancellationToken cancellationToken = default )
200- {
201- throw new NotImplementedException ( ) ;
202- }
203-
204- public Task < Result < BlobMetadata > > UploadAsync ( string content , CancellationToken cancellationToken = default )
205- {
206- throw new NotImplementedException ( ) ;
207- }
208-
209- public Task < Result < BlobMetadata > > UploadAsync ( FileInfo fileInfo , CancellationToken cancellationToken = default )
210- {
211- throw new NotImplementedException ( ) ;
212- }
213-
214- public Task < Result < BlobMetadata > > UploadAsync ( Stream stream , UploadOptions options , CancellationToken cancellationToken = default )
194+ public async Task < Result < Stream > > GetFileStream ( string fileName , string apiUrl , CancellationToken cancellationToken = default )
215195 {
216- throw new NotImplementedException ( ) ;
217- }
218-
219- public Task < Result < BlobMetadata > > UploadAsync ( byte [ ] data , UploadOptions options , CancellationToken cancellationToken = default )
220- {
221- throw new NotImplementedException ( ) ;
222- }
223-
224- public Task < Result < BlobMetadata > > UploadAsync ( string content , UploadOptions options , CancellationToken cancellationToken = default )
225- {
226- throw new NotImplementedException ( ) ;
227- }
228-
229- public Task < Result < BlobMetadata > > UploadAsync ( FileInfo fileInfo , UploadOptions options , CancellationToken cancellationToken = default )
230- {
231- throw new NotImplementedException ( ) ;
232- }
233-
234- public Task < Result < BlobMetadata > > UploadAsync ( Stream stream , Action < UploadOptions > action , CancellationToken cancellationToken = default )
235- {
236- throw new NotImplementedException ( ) ;
237- }
238-
239- public Task < Result < BlobMetadata > > UploadAsync ( byte [ ] data , Action < UploadOptions > action , CancellationToken cancellationToken = default )
240- {
241- throw new NotImplementedException ( ) ;
242- }
243-
244- public Task < Result < BlobMetadata > > UploadAsync ( string content , Action < UploadOptions > action , CancellationToken cancellationToken = default )
245- {
246- throw new NotImplementedException ( ) ;
247- }
248-
249- public Task < Result < BlobMetadata > > UploadAsync ( FileInfo fileInfo , Action < UploadOptions > action , CancellationToken cancellationToken = default )
250- {
251- throw new NotImplementedException ( ) ;
252- }
253-
254- public Task < Result < LocalFile > > DownloadAsync ( string fileName , CancellationToken cancellationToken = default )
255- {
256- throw new NotImplementedException ( ) ;
257- }
258-
259- public Task < Result < LocalFile > > DownloadAsync ( DownloadOptions options , CancellationToken cancellationToken = default )
260- {
261- throw new NotImplementedException ( ) ;
262- }
196+ try
197+ {
198+ var response = await _httpClient . GetAsync ( $ "{ apiUrl } /{ fileName } ") ;
199+ if ( response . IsSuccessStatusCode )
200+ {
201+ var stream = await response . Content . ReadAsStreamAsync ( ) ;
202+ return Result < Stream > . Succeed ( stream ) ;
203+ }
263204
264- public Task < Result < LocalFile > > DownloadAsync ( Action < DownloadOptions > action , CancellationToken cancellationToken = default )
265- {
266- throw new NotImplementedException ( ) ;
205+ return Result < Stream > . Fail ( response . StatusCode ) ;
206+ }
207+ catch ( HttpRequestException e ) when ( e . StatusCode != null )
208+ {
209+ return Result < Stream > . Fail ( e . StatusCode . Value ) ;
210+ }
211+ catch ( Exception )
212+ {
213+ return Result < Stream > . Fail ( HttpStatusCode . InternalServerError ) ;
214+ }
267215 }
268216}
0 commit comments