public async Task <ServiceResult <LoadedImage, LoadImageError> > LoadImageAsync(string externalId) { var imagesRepository = _unitOfWork.GetRepository <UploadedImage>(); var imageDetails = await imagesRepository.SingleOrDefaultAsync(i => i.ExternalId == externalId); if (imageDetails == null) { return(ServiceResult <LoadedImage, LoadImageError> .CreateFailed(LoadImageError.IncorrectExternalId)); } var imageExtension = Path.GetExtension(imageDetails.FilePath); var imageName = $"{externalId}{imageExtension}"; var firebaseStorage = new FirebaseStorage(_firebaseImageStorageConfiguration.StorageBucket) .Child(_firebaseImageStorageConfiguration.ImagesDirectory) .Child(imageName); try { var fileBytes = await firebaseStorage.GetAsync(imageDetails.FilePath); return(ServiceResult <LoadedImage, LoadImageError> .CreateSuccess(new LoadedImage(fileBytes, imageDetails.MediaType))); } catch (FirebaseStorageException) { return(ServiceResult <LoadedImage, LoadImageError> .CreateFailed(LoadImageError.ImageNotExists)); } }