尝试在Blob存储触发函数中引用CloudBlockBlob时出现编译错误

时间:2018-09-25 07:39:35

标签: c# azure azure-functions azure-storage-blobs

这是我的功能代码。

#r "Microsoft.WindowsAzure.Storage.Blob"

public static async Task Run(CloudBlockBlob uploadedVideo, string name, CloudBlockBlob processedVideo, ILogger log)
{
    log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {uploadedVideo.Length} Bytes");
    var fileEntry = new 
    {
        fileName = $"uploaded-videos/{name}",
        fileType = "video",
        correlationId = Guid.NewGuid()
    };
    await processedVideo.StartCopyAsync(uploadedVideo);  
    await uploadedVideo.DeleteIfExistsAsync();
}

这是我的function.json

{
  "bindings": [
    {
      "name": "uploadedVideo",
      "type": "blobTrigger",
      "direction": "in",
      "path": "uploaded-videos/{name}",
      "connection": "AzureWebJobsStorage"
    },
    {
      "type": "blob",
      "name": "processedVideo",
      "path": "processed-videos/{name}-{rand-guid}",
      "connection": "AzureWebJobsStorage",
      "direction": "out"
    }
  ]
}

这是我运行此函数时始终抛出的错误。

  

2018-09-25T07:34:10.813 [错误]函数编译错误   2018-09-25T07:34:10.982 [错误] BlobTriggerCSharp.csx(2,1):错误CS0006:找不到元数据文件'Microsoft.WindowsAzure.Storage.Blob'   2018-09-25T07:34:11.040 [错误] BlobTriggerCSharp.csx(4,30):错误CS0246:找不到类型或名称空间名称'CloudBlockBlob'(您是否缺少using指令或程序集引用?)   2018-09-25T07:34:11.128 [错误] BlobTriggerCSharp.csx(4,73):错误CS0246:找不到类型或名称空间名称'CloudBlockBlob'(您是否缺少using指令或程序集引用?)< / p>

1 个答案:

答案 0 :(得分:4)

没有Microsoft.WindowsAzure.Storage.Blob程序集,它是Microsoft.WindowsAzure.Storage中包含的名称空间。程序集和名称空间应按以下方式使用。

#r "Microsoft.WindowsAzure.Storage"

using Microsoft.WindowsAzure.Storage.Blob;

CloudBlockBlob不能直接获取Length属性,我们必须首先获取blob属性。

await uploadedVideo.FetchAttributesAsync();
log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {uploadedVideo.Properties.Length} Bytes");