private static CloudBlob GetBlobReference(CloudBlobDirectory directory, CloudBlob blob) { CloudBlob cloudBlob = null; // [longwen] You can use cloudBlob.BlobType to check the blob type here switch (blob.GetType().Name) { case nameof(CloudBlockBlob): cloudBlob = directory.GetBlockBlobReference(blob.Name); break; case nameof(CloudPageBlob): cloudBlob = directory.GetPageBlobReference(blob.Name); break; case nameof(CloudAppendBlob): cloudBlob = directory.GetAppendBlobReference(blob.Name); break; default: throw new Exception("Unknown CloudBlob type"); } return(cloudBlob); }
public async Task Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req, [Queue("queue-chatxx-images")] IAsyncCollector <Message> queue, [Blob("storage-chatxx/images")] CloudBlobDirectory container , [SignalR(HubName = "chat")] IAsyncCollector <SignalRMessage> signalRMessages ) { var form = await req.ReadFormAsync(); var name = form[nameof(Message.Name).ToLowerInvariant()].Single(); var file = form.Files.Single(); var message = new Message { Name = "<i>system</i>", Content = $"<i>{name} uploaded {file.FileName} {file.Length} bytes, processing..</i>" }; var format = new SignalRMessage { Target = "newMessage", Arguments = new Message[1] { message } }; await signalRMessages.AddAsync(format); var pref = DateTime.Now.Ticks.ToString("X16"); var xx = container.GetAppendBlobReference($"{pref}_{file.FileName}"); await xx.CreateOrReplaceAsync(); await xx.AppendFromStreamAsync(file.OpenReadStream()); await queue.AddAsync(new Message { Name = name, Tags = new[] { nameof(file), xx.Uri.AbsoluteUri, nameof(file.ContentType), file.ContentType, nameof(file.Length), $"{file.Length} bytes", } }); }
public virtual CloudAppendBlobEx GetAppendBlobReference(string blobName) { if (blobName == null) { throw new ArgumentNullException(nameof(blobName)); } CloudAppendBlob[] cloudAppendBlobArray = new CloudAppendBlob[this.failoverExecutor.AllElements.Length]; for (int i = 0; i < this.failoverExecutor.AllElements.Length; i++) { CloudBlobDirectory directory = this.failoverExecutor.AllElements[i]; CloudAppendBlob cloudAppendBlob = directory.GetAppendBlobReference(blobName); cloudAppendBlobArray[i] = cloudAppendBlob; } CloudAppendBlobEx cloudAppendBlobEx = new CloudAppendBlobEx(this.Container, this.failoverExecutor.FailoverToken, cloudAppendBlobArray); return(cloudAppendBlobEx); }
public CloudAppendBlob GetAppendBlob(string containerName, string directoryPath, string fileName, bool fetchAttributes) { CloudAppendBlob blob; CloudBlobContainer container = GetBlobContainer(containerName); if (string.IsNullOrEmpty(directoryPath)) { blob = container.GetAppendBlobReference(fileName); } else { CloudBlobDirectory directory = container.GetDirectoryReference(directoryPath); blob = directory.GetAppendBlobReference(fileName); } if (fetchAttributes) { blob.FetchAttributesAsync().Wait(); } return(blob); }