public async Task <IActionResult> DownloadImage([FromRoute] GetImageQuery query, CancellationToken cancellationToken) { var image = await _mediator.Send(query, cancellationToken); var extension = image.Name.Split('.').Last(); return(File(image, GetMimeType(extension))); }
public async Task <IActionResult> Get(string name, int width, int height, string type, string watermark = "", string backgroundColor = "") { // Get the requested ETag string requestETag = ""; if (Request.Headers.ContainsKey("If-None-Match")) { requestETag = Request.Headers["If-None-Match"].First(); } //check distributed cache (Redis) if we had this exact request previously and we have it in cache! string concatenatedKey = GetConcatenatedKey(name, width, height, type, watermark, backgroundColor); FileContentResult fcr = null; string key = GenerateHashKey(concatenatedKey); byte[] imageBytes; if (redisCacheService.HasValudBeenCached(key).Result) { //we have this in cache! imageBytes = redisCacheService.GetCachedValueAsync(key).Result; } else { GetImageQuery query = GetImageQueryObject(name, width, height, type, watermark, backgroundColor); //Using CQRS technique to send the query to the mediatR var result = await Mediator.Send(query); imageBytes = result.Data.ImageByteArray; //Cache it now redisCacheService.SetCacheValueAsync(key, imageBytes); } // Construct the new ETag string responseETag = key; // Return a 304 if the ETag of the current record matches the ETag in the "If-None-Match" HTTP header if (Request.Headers.ContainsKey("If-None-Match") && responseETag == requestETag) { return(Ok(StatusCode((int)HttpStatusCode.NotModified))); } // Add the current ETag to the HTTP header Response.Headers.Add("ETag", responseETag); fcr = GetImageFile(type, imageBytes); return(fcr); }
public Task <Response <ImageViewModel> > Handle(GetImageQuery request, CancellationToken cancellationToken) { var newImageSize = _fileHandler.GetResizedImage(request.ImageFileNamePath, request.Width, request.Height, request.Watermark, request.BackgroundColor); var ret = new ImageViewModel() { ImageByteArray = newImageSize }; var ret2 = new Response <ImageViewModel>() { Data = ret, Succeeded = true, Message = "Successfully resized" }; return(Task.FromResult(ret2)); }
public FileContentResult Img(GetImageQuery query) { var img = this.dispatcher.Query(query); return(File(img, "img")); }