public static void ProcessImageQueueMessage( [QueueTrigger("images")] Common.Entities.Image img, [Blob("images/uploads/{Id}")] CloudBlockBlob uploadedBlob, [Blob("images/handled/{Id}.img")] CloudBlockBlob outputBlob, [Blob("images/handled/{Id}_thumbnail.img")] CloudBlockBlob outputThumbnailBlob, [Table("images")] CloudTable imageTable, [ServiceBus("images")] out string message, TextWriter log) { log.WriteLine("Got message from queue to process image: " + img.Source + ", with ID: " + img.RowKey); using (var input = new MemoryStream()) { uploadedBlob.DownloadToStream(input); using (var output = outputThumbnailBlob.OpenWrite()) { ProcessImage(img.ContentType, input, output, quality: 70, maxWidth: 150); outputThumbnailBlob.Properties.ContentType = img.ContentType; outputThumbnailBlob.Properties.CacheControl = "public, max-age=31536000"; // 1 year cache } log.WriteLine("Created thumbnail for " + img.Id); using (var output = outputBlob.OpenWrite()) { ProcessImage(img.ContentType, input, output, quality: 90, maxWidth: 1920); outputBlob.Properties.ContentType = img.ContentType; outputBlob.Properties.CacheControl = "public, max-age=31536000"; // 1 year cache } } log.WriteLine("Created full image for " + img.Id); // Insert to table storage img.Source = outputBlob.Uri.AbsolutePath; img.Thumbnail = outputThumbnailBlob.Uri.AbsolutePath; var opp = TableOperation.Insert(img); imageTable.Execute(opp); log.WriteLine("Inserted outputted image for " + img.Id); //using (var m = new MemoryStream()) //{ // using (var t = new StreamWriter(m)) // { // t.Write("ImageUploaded"); // t.Flush(); // } // message = new BrokeredMessage(m); //} message = "ImageUploaded"; uploadedBlob.DeleteIfExists(); log.WriteLine("Message to service bus assigned"); }
public async Task ImageUploadCompleteAsync(string contentType, string storageUrl) { if (string.IsNullOrEmpty(contentType)) { throw new ArgumentNullException("contentType"); } if (string.IsNullOrEmpty(storageUrl)) { throw new ArgumentNullException("storageUrl"); } var uri = new Uri(storageUrl); var id = Path.GetFileNameWithoutExtension(uri.AbsolutePath); var img = new Common.Entities.Image { PartitionKey = Guid.NewGuid().ToString("N"), RowKey = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"), Id = id, ContentType = contentType }; var message = JsonConvert.SerializeObject(img); var queueMessage = new CloudQueueMessage(message); await _queue.AddMessageAsync(queueMessage); }