首页 > 解决方案 > 如何获取存储在 ADLS Gen2 中的文件的 MD5?

问题描述

我通过 sFTP 将每日文件接收到 ADLS gen 2 存储帐户。我需要通过检查存储在 ADLS gen2 中的文件的 MD5 来验证文件。

我尝试使用 BLOB API,目前它不支持 ADLS gen2。如果文件存储在 Blob 存储中,我能够从 Blob 属性中获取 Content MD5。

有人可以帮助如何从 ADLS gen 2 获取内容 MD5 吗?

标签: azure

解决方案


如您所知,目前不支持 Blob api,但您可以查看Data Lake Storage Gen2 rest api-> Path - Get Properties,它可用于获取存储在 ADLS Gen2 中的文件的属性。

这是一个示例代码(请注意,我使用附加到 api url 的 sas 令牌):

using System;
using System.Net;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            string sasToken = "?sv=2018-03-28&ss=b&srt=sco&sp=rwdl&st=2019-04-15T08%3A07%3A49Z&se=2019-04-16T08%3A07%3A49Z&sig=xxxx";
            string url = "https://xxxx.dfs.core.windows.net/myfilesys1/app.JPG" + sasToken;
            var req = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
            req.Method = "HEAD";
            var res = (HttpWebResponse)req.GetResponse();

            Console.WriteLine("the status code is: "+res.StatusCode);

            var headers = res.Headers;
            Console.WriteLine("the count of the headers is: "+headers.Count);
            Console.WriteLine("*********");
            Console.WriteLine();

            //list all the properties if you don't know which correct format of property.
            foreach (var h in headers.Keys)
            {
                Console.WriteLine(h.ToString());
            }
            Console.WriteLine("*********");
            Console.WriteLine();

            //take the Content-Type property for example.
            var myheader = res.GetResponseHeader("Content-Type");
            Console.WriteLine($"the header Content-Type is: {myheader}");

            Console.ReadLine();
        }
    }
}

结果:

在此处输入图像描述

如果您不知道如何生成 sas 令牌,您可以导航到 azure 门户 -> 您的存储帐户,然后按照下面的屏幕截图进行操作:

在此处输入图像描述


推荐阅读