public new async Task <string> Patch(Request r) { var file = Request.Files.FirstOrDefault(); if (file == null) { ThrowError("No file data was detected in the request!"); } if (!IsAllowedSize(file.ContentLength)) { AddError("The file size is not acceptable!"); } if (!IsAllowedType(file.ContentType)) { AddError("Only JPG or PNG format is allowed!"); } ThrowIfAnyErrors(); if (r.ID.HasValue()) { _ = RepoImage.DeleteAsync(r.ID); //delete old image (cause of cloudflare caching) and nullify image ID so a new ID will be set } r.ID = null; using var strInput = file.InputStream; using var img = SixLabors.ImageSharp.Image.Load(strInput); img.Mutate( x => x.Resize(new ResizeOptions { Mode = ResizeMode.Crop, Size = new Size { Width = r.Width, Height = r.Height } })); using var strOutput = new MemoryStream(); img.SaveAsJpeg(strOutput, new JpegEncoder { Quality = 80 }); return(await RepoImage.UploadAsync(r.ToEntity(), strOutput)); }
public new async Task Get(Request r) { HttpResponse.ContentType = "image/jpeg"; try { HttpResponse.StatusCode = 200; await RepoImage.DownloadAsync(r.ID, HttpResponse.OutputStream); } catch (Exception) { HttpResponse.StatusCode = 404; } finally { HttpResponse.EndRequest(); } }
public override Nothing Delete(Request r) { _ = RepoImage.DeleteAsync(r.ID); return(Nothing); }