问题
The blob reference contains a Properties property that has a LastModified of DateTimeOffset?. However, I can't find when was the creation date(time) of the blob. Is there a standard API I can use or I need to store that in the meta?
public async Task<IBlobMeta> GetBlobMetaAsync(string blobId)
{
if (IsNullOrWhiteSpace(blobId))
throw new ArgumentException("Value cannot be null or whitespace.", nameof(blobId));
var blob = await EnsureGetBlobById(blobId);
await blob.FetchAttributesAsync();
string clientBlobName;
blob.Metadata.TryGetValue(BlobNameMetaKey, out clientBlobName);
var length = blob.Properties.Length;
var md5 = blob.Properties.ContentMD5;
var lastModified = blob.Properties.LastModified.Value.ToUniversalTime().DateTime;
var dateCreated= blob.Properties.???????;
return new AzureBlobMeta(blobId, clientBlobName, length, md5, dateCreated);
}
回答1:
The Created date property has been added in Storage Client Library, starting with version 9.2.0:
Blobs: Added support for blob creation time property.
(Available on Nuget since May 23 '18)
Here's how it's declared in BlobProperties.cs:
/// <summary>
/// Gets the the creation time for the blob, expressed as a UTC value.
/// </summary>
/// <value>A <see cref="DateTimeOffset"/> containing the blob's creation time, in UTC format.</value>
public DateTimeOffset? Created { get; internal set; }
The type is nullable DateTimeOffset, same as LastModified property.
The source of the value comes from x-ms-creation-time header in the REST API, which was added in version 2017-11-09:
x-ms-creation-timeVersion 2017-11-09 and newer. The date/time at which the blob was created. The date format follows RFC 1123.
回答2:
Is there a standard API I can use or I need to store that in the meta?
As of today, you would need to store this information in form of blob metadata. There's no API which would tell you when a blob was created. Last Modified property of the blob tells you when a blob was last modified. This could be because a blob's content was changed or either it's properties or metadata was changed.
来源:https://stackoverflow.com/questions/41287749/when-was-a-block-blob-created-in-azure