Azure函数中作为输入绑定的Blob流使用哪个LocationMode获取输入流

问题描述 投票:0回答:1

我正在使用Blob作为输入绑定来获取Blob流作为输入,然后对该流文本进行处理。对于灾难恢复,我需要在函数获取输入流时将LocationMode(Microsoft.Azure.Storage.RetryPolicies)称为“ PrimaryThenSecondary”。在这种情况下,默认的LocationMode是什么以及如何更改它。

下面是如何使用Blob输入绑定-

[FunctionName("FunctionName")]
        public async Task RunAsync(
            [EventGridTrigger]EventGridEvent eventGridEvent,
            [Blob("{data.url}", FileAccess.Read, Connection = "BlobStorageConnectionString")]Stream input,
            [Table("TableName", Connection = "BlobStorageConnectionString")]CloudTable cloudTable,
            ILogger log)
        {
          //Some code

          //To get the data in blob
          StreamReader streamReader = new StreamReader(input);
          string blobData = await streamReader.ReadToEndAsync();
        }

我看到的控制它的一种方法是-获取CloudBlockBlob而不是流作为输入

[FunctionName("FunctionName")]
        public async Task RunAsync(
            [EventGridTrigger]EventGridEvent eventGridEvent,
            [Blob("{data.url}", FileAccess.Read, Connection = "BlobStorageConnectionString")]CloudBlockBlob input,
            [Table("TableName", Connection = "BlobStorageConnectionString")]CloudTable cloudTable,
            ILogger log)
        {
          //Some code to get the stream using 
          // Task DownloadToFileAsync(string path, FileMode mode, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext);
        }
azure azure-functions azure-storage-blobs
1个回答
0
投票

在这种情况下默认的LocationMode是什么以及如何更改它。

您可以使用getLocationMode获取此请求的默认位置模式。

并使用getLocationMode属性设置请求的位置模式。

BlobRequestOptions.LocationMode

BlobRequestOptions.LocationMode包含locationModeRequestOptions = new BlobRequestOptions() { LocationMode = RetryPolicies.LocationMode.PrimaryThenSecondary }; byteCount = blob.DownloadToByteArray(destinationArray, index: 0, accessCondition: null, options: locationModeRequestOptions); LocationModePrimaryOnlyPrimaryThenSecondary。有关更多详细信息,您可以参考此SecondaryOnly

© www.soinside.com 2019 - 2024. All rights reserved.