在 Azure 中访问 Blob 属性
Access Blob Properties in Azure
我需要获取 blob 属性,其中有一个最后修改日期。我需要日期进行比较。看了很多文章,以为是因为我没有使用 CloudBlockBlob,但我无法从中提取属性。
到目前为止我的代码returns blob 的名称:
public static void ListBlobsAnonymously()
{
//Get the blob from the URL - URL is in the app.config file so it can be changed easily should it need it.
CloudBlobContainer container = new CloudBlobContainer(new Uri(ConfigurationManager.AppSettings["VOURL"]));
//For each of the blobs, write the file name out. This will be needed for a comparison.
foreach (IListBlobItem blobItem in container.ListBlobs())
{
string name = blobItem.Uri.Segments.Last();
Console.WriteLine(name);
}
Console.ReadKey();
}
这是 blob 的结构:
<EnumerationResults ServiceEndpoint="https://test.blob.core.windows.net/" ContainerName="downloads">
<Blobs>
<Blob>
<Name>
This_is_a_test
</Name>
<Properties>
<Last-Modified>Tue, 01 Oct 2010 14:33:48 GMT</Last-Modified>
<Content-Length>452</Content-Length>
<Content-Type>application/zip</Content-Type>
<BlobType>BlockBlob</BlobType>
</Properties>
</Blob>
</Blobs>
</EnumerationResults>
这是属性中的最后修改,我需要掌握但不能。
试试这个代码:(注意:不是 supported/working 在 NET Core 上)
CloudBlobContainer container = new CloudBlobContainer(new Uri(ConfigurationManager.AppSettings["VOURL"]));
//For each of the blobs, write the file name out. This will be needed for a comparison.
foreach (IListBlobItem blobItem in container.ListBlobs())
{
var blob = (CloudBlob)blobItem;
if (blob != null)
{
string name = blobItem.Uri.Segments.Last();
Console.WriteLine(name);
Console.WriteLine(blob.Properties.LastModified);
}
}
Console.ReadKey();
基本上,您需要将 IListBlobItem
转换为 CloudBlob
,这样您就可以访问 blob 的属性。
我需要获取 blob 属性,其中有一个最后修改日期。我需要日期进行比较。看了很多文章,以为是因为我没有使用 CloudBlockBlob,但我无法从中提取属性。
到目前为止我的代码returns blob 的名称:
public static void ListBlobsAnonymously()
{
//Get the blob from the URL - URL is in the app.config file so it can be changed easily should it need it.
CloudBlobContainer container = new CloudBlobContainer(new Uri(ConfigurationManager.AppSettings["VOURL"]));
//For each of the blobs, write the file name out. This will be needed for a comparison.
foreach (IListBlobItem blobItem in container.ListBlobs())
{
string name = blobItem.Uri.Segments.Last();
Console.WriteLine(name);
}
Console.ReadKey();
}
这是 blob 的结构:
<EnumerationResults ServiceEndpoint="https://test.blob.core.windows.net/" ContainerName="downloads">
<Blobs>
<Blob>
<Name>
This_is_a_test
</Name>
<Properties>
<Last-Modified>Tue, 01 Oct 2010 14:33:48 GMT</Last-Modified>
<Content-Length>452</Content-Length>
<Content-Type>application/zip</Content-Type>
<BlobType>BlockBlob</BlobType>
</Properties>
</Blob>
</Blobs>
</EnumerationResults>
这是属性中的最后修改,我需要掌握但不能。
试试这个代码:(注意:不是 supported/working 在 NET Core 上)
CloudBlobContainer container = new CloudBlobContainer(new Uri(ConfigurationManager.AppSettings["VOURL"]));
//For each of the blobs, write the file name out. This will be needed for a comparison.
foreach (IListBlobItem blobItem in container.ListBlobs())
{
var blob = (CloudBlob)blobItem;
if (blob != null)
{
string name = blobItem.Uri.Segments.Last();
Console.WriteLine(name);
Console.WriteLine(blob.Properties.LastModified);
}
}
Console.ReadKey();
基本上,您需要将 IListBlobItem
转换为 CloudBlob
,这样您就可以访问 blob 的属性。