【问题标题】:MD5 value of upload file上传文件的MD5值
【发布时间】:2019-04-09 17:50:59
【问题描述】:

我正在尝试使用 Http Trigger 使用 Azure 函数提取上传 blob 的 MD5 和长度(大小),下面是我正在试验的代码,但我总是得到 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");
}

【问题讨论】:

  • 如果答案对您有用,请帮助将其标记为答案。谢谢。

标签: azure azure-storage


【解决方案1】:

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

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

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

【讨论】:

  • 我尝试使用上述方法,但它抛出了 BLOB API 可以使用。我试图从 ADLS Gen2 获取 blob 的属性,似乎不支持 blob api。知道如何获取存储在 ADLS Gen2 上的文件的 md5 吗?
  • @sathishkumarkandhaswamy,你能看看Azure Data Lake Store Gen2 REST API吗?如果您有任何问题,请告诉我。
  • @sathishkumarkandhaswamy,我在你的另一个question中举了一个例子来说明如何使用 Gen2 rest api 来获取这些属性。
猜你喜欢
  • 2018-12-30
  • 2018-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多