Exemplo n.º 1
0
        public virtual async Task <Blob> GetBlobReferenceAsync(string containerName, string blobId)
        {
            Utility.AssertNotNullOrEmpty(nameof(blobId), blobId);
            var retrieveBlobApiCallresult = await this.BlobsApiClient.GetBlobByIdAsync(blobId);

            if (false == retrieveBlobApiCallresult.ResponseMessage.IsSuccessStatusCode)
            {
                if (retrieveBlobApiCallresult.ResponseMessage.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    throw ExceptionGenerator.BlobNotFoundException(blobId);
                }
                else
                {
                    throw ExceptionGenerator.GeneralFailureException(retrieveBlobApiCallresult.StringContent);
                }
            }

            var blobDTO = retrieveBlobApiCallresult.GetContent();

            var container = await GetContainerReferenceAsync(containerName);

            var blob = new Blob(this, container, blobDTO.Id, blobDTO.OrigFileName,
                                blobDTO.MimeType, blobDTO.SizeInBytes, blobDTO.DownloadRelativeUrl);

            return(blob);
        }
Exemplo n.º 2
0
        public virtual async Task <Stream> OpenReadAsync(CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            var serviceResponse = await _blobApi.RawBlobAsync(this.Id);

            if (false == serviceResponse.ResponseMessage.IsSuccessStatusCode)
            {
                if (serviceResponse.ResponseMessage.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    throw ExceptionGenerator.BlobNotFoundException(this.Id);
                }
                else
                {
                    throw ExceptionGenerator.GeneralFailureException(serviceResponse.StringContent);
                }
            }

            return(await serviceResponse.ResponseMessage.Content.ReadAsStreamAsync());
        }