public async Task ZipIt([ActivityTrigger] BlobModel input, Binder binder) { SemaphoreSlim semaphore = GetSemaphoreForContainer(input.Analysis.Category); await semaphore.WaitAsync(); try { string name = $"{input.Analysis.Category}.zip"; using Stream zipStream = await binder.BindAsync <Stream>(FunctionUtils.GetBindingAttributes("zip-collection", name)); using var archive = new ZipArchive(zipStream, ZipArchiveMode.Create, true); BlobContainerClient containerClient = GetCloudBlobContainer(input.Analysis.Category); containerClient.DeleteBlobIfExists(name); Pageable <BlobItem> blobs = containerClient.GetBlobs(); foreach (BlobItem blob in blobs) { BlobClient client = containerClient.GetBlobClient(blob.Name); using var blobStream = new MemoryStream(); client.DownloadTo(blobStream); using Stream entryStream = archive.CreateEntry(blob.Name).Open(); blobStream.Seek(0, SeekOrigin.Begin); blobStream.CopyTo(entryStream); } } finally { semaphore.Release(); } }
public async Task Upload([ActivityTrigger] BlobModel input, Binder binder) { // Use a binder to dynamically set the binding output path using Stream fileOutputStream = await binder.BindAsync <Stream>(FunctionUtils.GetBindingAttributes(input.Analysis.Category, input.Name)); await fileOutputStream.WriteAsync(input.Blob, 0, input.Blob.Length); }
public async Task CreateThumbnail([ActivityTrigger] BlobModel input, Binder binder) { using Stream thumbnail = await binder.BindAsync <Stream>(FunctionUtils.GetBindingAttributes($"{input.Analysis.Category}-thumbs", input.Name)); using Image <Rgba32> image = Image.Load(input.Blob); image.Mutate(i => { i.Resize(340, 0); int height = i.GetCurrentSize().Height; i.Crop(new Rectangle(0, 0, 340, height < 226 ? height : 226)); }); image.SaveAsJpeg(thumbnail); }