【问题标题】:How to get MD5 of file stored in ADLS Gen2?如何获取存储在 ADLS Gen2 中的文件的 MD5?
【发布时间】:2019-09-01 13:27:57
【问题描述】:

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

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

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

【问题讨论】:

    标签: azure


    【解决方案1】:

    如您所知,目前不支持 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 门户 -> 您的存储帐户,然后按照以下屏幕截图进行操作:

    【讨论】:

    • 在示例中,我以“Content-Type”属性为例。您可以将其更改为 MD5。请让我知道它是否有效。
    猜你喜欢
    • 1970-01-01
    • 2021-11-25
    • 2021-10-20
    • 2020-09-15
    • 1970-01-01
    • 2021-08-03
    • 1970-01-01
    • 2022-01-18
    • 2021-11-13
    相关资源
    最近更新 更多