public async Task <Result> Handle(DownloadFileQuery request, CancellationToken cancellationToken) { Result result; try { var fileDto = await _blobStorage.DownloadFileAsync(request.File); var fileModel = _mapper.Map <FileDownloadModel>(fileDto); result = Result.Ok(fileModel); } catch (BlobNotFoundException) { result = Result.Fail(new List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.NotFound.Name, Message = string.Format(HandlerFailures.NotFound, "File"), Target = "file" } }); } catch { result = Result.Fail(CustomFailures.DownloadFileFailure); } return(result); }
public void DownloadFileAsync_ShouldReturBlobItem_ForDownload() { _sut = new BlobStorage(_mockBlobContainerFactory.Object); _sut.DownloadFileAsync(It.IsAny <string>()); _mockBlobContainerFactory.Verify(v => v.GetBlockBlobClient(It.IsAny <string>(), It.IsNotNull <string>()), Times.Once); }
public async Task <IActionResult> Get(string blobName) { var stream = _blobStorage.DownloadFileAsync(blobName).Result; if (stream == null || stream.Length == 0) { return(NotFound("Blob does not exists")); } return(File(stream, "application/pdf")); }