上传文件的MD5值

时间:2019-04-09 08:44:29

标签: azure azure-storage

我正在尝试使用Http触发器使用Azure函数提取MD5和上载blob的长度(大小),下面是我正在尝试的代码,但我总是得到null和-1。请有人确认代码正确或其他任何选项可用


public static async Task<IActionResult> Run(HttpRequest req,string inputBlob, ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");

    string name = req.Query["name"];
    log.LogInformation($"name,{inputBlob}");
    log.LogInformation("Blob content: " + inputBlob.Properties.Length); //This is printing content of blob


    CloudBlockBlob blob;
   var credentials = new StorageCredentials("xxx", "xxxx");
   var client = new CloudBlobClient(new Uri("https://xxx.blob.core.windows.net"), credentials);
    var container = client.GetContainerReference("parent");
    blob = container.GetBlockBlobReference("file.csv");
    log.LogInformation("Blob details: " + blob.Properties.Length); //This is printing -1, if i provide ContentMD5 its showing null. Bascially its not able to read the blob 



    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);
    name = name ?? data?.name;

    return name != null
        ? (ActionResult)new OkObjectResult($"Hello, {name}")
        : new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}

1 个答案:

答案 0 :(得分:0)

在尝试检索Blob的任何属性之前,您缺少FetchAttributesAsync()(或FetchAttributes())方法。

//your other code
blob = container.GetBlockBlobReference("file.csv");
blob.FetchAttributesAsync()(); //or FetchAttributes()

//then you can try to get any property here.