我正在尝试在Azure数据工厂中构建一个自定义活动,该活动将blob作为输入数据集,并希望将此blob的sas标记路径传递给需要此类型路径的API。
有没有办法在自定义活动中使用sas令牌获取blob的路径?
答案 0 :(得分:1)
我想出了办法。 ADF v1中的部分自定义活动是具有上下文参数的Execute方法。从该上下文中,您可以获得blob存储的连接字符串和blob的路径,然后您可以像这样提取sas标记:
public override IDictionary<string, string> Execute(
AOMDotNetActivityContext context,
IActivityLogger logger)
{
string blobConnectionString = context.ConnectionString;
CloudStorageAccount inputStorageAccount = CloudStorageAccount.Parse(blobConnectionString);
var blob = new CloudBlob(new Uri(inputStorageAccount.BlobEndpoint, Path.Combine(context.FolderPath, context.FileName)), inputStorageAccount.Credentials);
SharedAccessBlobPolicy adHocSAS = new SharedAccessBlobPolicy()
{
SharedAccessExpiryTime = DateTime.UtcNow.AddHours(48),
Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Delete
};
string sasBlobToken = blob.GetSharedAccessSignature(adHocSAS);
string fullUri = new Uri(blob.Uri, sasBlobToken).ToString();