首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >上传文件的MD5值

上传文件的MD5值
EN

Stack Overflow用户
提问于 2019-04-09 08:44:28
回答 1查看 262关注 0票数 0

我试图使用HTTP触发器提取上传blob的MD5和长度(大小),但我总是得到null和-1。请有人确认代码是正确的或任何其他选项是可用的。

代码语言:javascript
复制
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");
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-09 09:50:59

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

代码语言:javascript
复制
//your other code
blob = container.GetBlockBlobReference("file.csv");
blob.FetchAttributesAsync()(); //or FetchAttributes()

//then you can try to get any property here.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55588560

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档