我通过 sFTP 将每日文件接收到 ADLS gen 2 存储帐户。我需要通过检查 ADLS gen2 中存储的文件的 MD5 来验证文件。
我尝试使用 BLOB API ,目前它不支持 ADLS gen2。如果文件存储在 Blob 存储中,我可以从 Blob 属性获取内容 MD5。
有人可以帮助如何从 ADLS gen 2 获取内容 MD5 吗?
如您所知,目前还不支持 Blob api,但您可以看一下Data Lake Storage Gen2 rest api
-> 路径 - 获取属性 https://learn.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/getproperties,可用于获取 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();
}
}
}
Result:
如果您不知道如何生成 sas 令牌,您可以导航到 azure 门户 -> 您的存储帐户,然后按照下面的屏幕截图操作:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)