我正在开发一组Azure函数来执行此高级过程
除了最后一部分之外,所有内容都可以正常工作。
将PDF上载到blob存储中后,我们可以访问请求元数据,但是blob触发器只能访问上载的PDF流。
我尝试了以下操作:
文档上传
var context = new OperationContext();
context.UserHeaders = new Dictionary<string, string>();
context.UserHeaders.Add("RowKey", entity.RowKey);
context.UserHeaders.Add("PartitionKey", entity.PartitionKey);
cloudBlockBlob.UploadFromStream(downloadedStream, operationContext: context);
Blob触发私有方法
public static void Run(
[BlobTrigger(FunctionConstants.PrintSetToBlobName, Connection = ConnectionStringName)]Stream myBlob,
string name,
TraceWriter log)
{
// code truncated for clarity
string documentUrl = GetDocumentUrl();
UpdateEntity(documentUrl);
}
private static void UpdateEntity(string documentUrl)
{
// This doesn't seem like it will work
OperationContext context = new OperationContext();
EntityService entityService = new EntityService();
context.UserHeaders.TryGetValue("RowKey", out string rowKey);
context.UserHeaders.TryGetValue("PartitionKey", out string partitionKey);
var entity = entityService.Get(rowKey, partitionKey);
entity.DocumentUrl = documentUrl;
entityService.Update(entity);
}
我尝试直接在{em> BlobTrigger.Run 函数中将OperationContext
作为参数传递,但由于它不是有效输入而导致运行时错误。
最终,我的问题是如何从 CloudBlockBlob.UploadFromStream 方法传递元数据并在Blob触发器中读取它?
答案 0 :(得分:2)
UserHeaders
设置请求的HTTP标头,以将Blob上传到Azure存储。这些标头在BlobTrigger
中不可用,因此您不能使用它们传递其他参数。
您可以将PartitionKey
和RowKey
保存到Blob元数据:
cloudBlockBlob.Metadata["PartitionKey"] = entity.PartitionKey;
cloudBlockBlob.Metadata["RowKey"] = entity.RowKey;
cloudBlockBlob.SetMetadata();
在您的其他函数中,将BlobTrigger
绑定到CloudBlockBlob
public static void Run(
[BlobTrigger(FunctionConstants.PrintSetToBlobName, Connection = ConnectionStringName)]CloudBlockBlob cloudBlockBlob,
string name,
TraceWriter log)
{
...
}
并读取元数据
cloudBlockBlob.FetchAttributes();
var partitionKey = cloudBlockBlob.Metadata["PartitionKey"];
var rowKey = cloudBlockBlob.Metadata["RowKey"];