public static async Task <string> ResizePicture([ActivityTrigger] PictureResizeRequest pictureResizeRequest, [Blob("photos", FileAccess.Read, Connection = "StorageConnection")] CloudBlobContainer photosContainer, [Blob("doneorders/{rand-guid}", FileAccess.ReadWrite, Connection = "StorageConnection")] ICloudBlob resizedPhotoCloudBlob, TraceWriter log) { var photoStream = await GetSourcePhotoStream(photosContainer, pictureResizeRequest.FileName); SetAttachmentAsContentDisposition(resizedPhotoCloudBlob, pictureResizeRequest); var image = Image.Load(photoStream); image.Mutate(e => e.Resize(pictureResizeRequest.RequiredWidth, pictureResizeRequest.RequiredHeight)); var resizedPhotoStream = new MemoryStream(); image.Save(resizedPhotoStream, new JpegEncoder()); resizedPhotoStream.Seek(0, SeekOrigin.Begin); await resizedPhotoCloudBlob.UploadFromStreamAsync(resizedPhotoStream); return(resizedPhotoCloudBlob.Name); }
private static void SetAttachmentAsContentDisposition(ICloudBlob resizedPhotoCloudBlob, PictureResizeRequest pictureResizeRequest) { resizedPhotoCloudBlob.Properties.ContentDisposition = $"attachment; filename={pictureResizeRequest.RequiredWidth}x{pictureResizeRequest.RequiredHeight}.jpeg"; }