public async Task <ActionResult> Get(int id) { try { var query = new ReadImageAssetQuery(id); var response = await mediator.Send(query); var blobClient = blobContainerClient.GetBlobClient(response.Guid.ToString()); var imageStream = blobClient.OpenRead(); return(new FileStreamResult(imageStream, new MediaTypeHeaderValue(response.ContentType))); } catch (NotFoundRequestException) { return(NotFound()); } }
public async Task <ActionResult <ImageAssetResource> > GetImageMetadata(int id) { try { var query = new ReadImageAssetQuery(id); var response = await mediator.Send(query); var imageAssetResource = new ImageAssetResource(response); imageAssetResource.EnrichWithLinks(this); return(imageAssetResource); } catch (NotFoundRequestException) { return(NotFound()); } }
public async Task <ActionResult <ImageAssetResource> > Post( [FromForm] IFormFile imageFormFile, [FromForm] int folderId) { EnsureArg.IsNotNull(imageFormFile); var formFileValidator = new FormFileValidator(); try { formFileValidator.ValidateForImage(imageFormFile); var command = new CreateImageAssetCommand(imageFormFile.OpenReadStream(), imageFormFile.FileName, imageFormFile.ContentType, folderId); var imageId = await mediator.Send(command); var query = new ReadImageAssetQuery(imageId); var response = await mediator.Send(query); var imageAssetResource = new ImageAssetResource(response); imageAssetResource.EnrichWithLinks(this); return(imageAssetResource); } catch (FileIsEmptyRequestException) { return(this.BadRequest(ApiErrors.FileIsEmpty)); } catch (FileNameContainsInvalidCharactersRequestException) { return(this.BadRequest(ApiErrors.FileContainsInvalidCharacters)); } catch (FileExtensionIsNotAcceptedRequestException) { return(this.BadRequest(ApiErrors.FileExtensionIsNotAccepted)); } catch (FileContentTypeIsNotAcceptedRequestException) { return(this.BadRequest(ApiErrors.FileContentTypeIsNotAccepted)); } catch (ParentFolderDoesNotExistRequestException) { return(this.BadRequest(ApiErrors.ParentFolderDoesNotExist)); } catch (FileNameMustBeUniqueInFolderRequestException) { return(this.BadRequest(ApiErrors.FileNameMustBeUniqueInFolder)); } }