I am writing a v2 Azure Function in which I will access Azure Blob Storage. Because I was having trouble, I reduced it down to this minimal example.
namespace Test
{
public static class Function1
{
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "test")] HttpRequest req,
ILogger log)
{
var azureStorage = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
var blobClient = azureStorage.CreateCloudBlobClient();
var container = blobClient.GetContainerReference("migrated-load-sets-localhost");
var blobReference = container.GetBlockBlobReference("11016093-2f6e-4631-97c1-04f8acfb2370");
var memoryStream = new MemoryStream();
var accessCondition = AccessCondition.GenerateIfExistsCondition();
var blobRequestOptions = new BlobRequestOptions();
await blobReference.DownloadToStreamAsync(memoryStream, accessCondition, blobRequestOptions, null);
var text = System.Text.Encoding.UTF8.GetString(memoryStream.ToArray());
return new OkObjectResult(text);
}
}
}
When I run and hit this, I get the error
System.Private.CoreLib: Exception while executing function: Function1. Microsoft.WindowsAzure.Storage: The format of value '*' is invalid. System.Net.Http: The format of value '*' is invalid.
If I change
var accessCondition = AccessCondition.GenerateIfExistsCondition();
to be
var accessCondition = AccessCondition.GenerateEmptyCondition();
it works.
I have observed in debugging that accessCondition.IfMatchETag
equals "*"
, so it seems like that might be the culprit.
Am I doing something wrong when I use AccessCondition.GenerateIfExistsCondition()
, or is there a bug in the library?
In case if you need to check if the blob is present before downloading the file , all you need is
if(blobReference.ExistsAsync())
{
//Download
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.