azure - 如何获取存储在 ADLS Gen2 中的文件的 MD5?
问题描述
我通过 sFTP 将每日文件接收到 ADLS gen 2 存储帐户。我需要通过检查存储在 ADLS gen2 中的文件的 MD5 来验证文件。
我尝试使用 BLOB API,目前它不支持 ADLS gen2。如果文件存储在 Blob 存储中,我能够从 Blob 属性中获取 Content MD5。
有人可以帮助如何从 ADLS gen 2 获取内容 MD5 吗?
解决方案
如您所知,目前不支持 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 门户 -> 您的存储帐户,然后按照下面的屏幕截图进行操作:
推荐阅读
- .net - 在 .NET core 和 .NET 4.6.1 中引用 .NET 标准 dll,System.Data.SqlClient 会引发 PlatformNotSupportedException
- java - JPA 实体在转换为 JSON 时会给出 stackoverflow 错误,但在使用 POJO 时不会
- css - 使用 CSS flexbox 和 grid 布局此 ui 的最佳方法
- vim - 在不打开文件的情况下启动后无法在 gvim 8.1 中离开插入模式
- python - python3使用日志记录容器中的所有元素(列表或元组)
- r - 用“矩阵”替换“矩阵”行时出错
- bash - awk bash 递归括号 id sed tr
- javascript - 组件父级上的键修饰符
- node.js - Heroku 和 multer
- wix - 在 WiX 中将 Zip 文件添加到 TARGETDIR