【发布时间】: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