Skip to content

Commit 42377cd

Browse files
authored
Added CreationTime and LastModified to blob metadata (#33)
1 parent 683dcb5 commit 42377cd

7 files changed

Lines changed: 33 additions & 12 deletions

File tree

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1414
<PackageReadmeFile>README.md</PackageReadmeFile>
1515
<Product>Managed Code - Storage</Product>
16-
<Version>2.0.6</Version>
17-
<PackageVersion>2.0.6</PackageVersion>
16+
<Version>2.0.7</Version>
17+
<PackageVersion>2.0.7</PackageVersion>
1818
</PropertyGroup>
1919
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
2020
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>

ManagedCode.Storage.Aws/AWSStorage.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,12 @@ public override async IAsyncEnumerable<BlobMetadata> GetBlobMetadataListAsync(st
7070

7171
yield return new BlobMetadata
7272
{
73+
Name = entry.Key,
7374
FullName = entry.Key,
74-
Name = Path.GetFileName(entry.Key),
75+
Container = StorageOptions.Bucket,
7576
Uri = new Uri($"https://s3.amazonaws.com/{StorageOptions.Bucket}/{entry.Key}"),
77+
LastModified = objectMetaResponse.LastModified,
78+
CreationTime = objectMetaResponse.LastModified,
7679
MimeType = objectMetaResponse.Headers.ContentType,
7780
Length = objectMetaResponse.Headers.ContentLength
7881
};
@@ -135,7 +138,7 @@ protected override async Task<Result<BlobMetadata>> UploadInternalAsync(Stream s
135138
InputStream = stream,
136139
AutoCloseStream = false,
137140
ContentType = options.MimeType,
138-
ServerSideEncryptionMethod = null
141+
ServerSideEncryptionMethod = null,
139142
};
140143

141144
try
@@ -162,11 +165,13 @@ protected override async Task<Result<LocalFile>> DownloadInternalAsync(LocalFile
162165

163166
localFile.BlobMetadata = new BlobMetadata
164167
{
165-
Name = options.FullPath,
168+
Name = options.FileName,
169+
Container = StorageOptions.Bucket,
166170
Uri = new Uri($"https://s3.amazonaws.com/{StorageOptions.Bucket}/{options.FullPath}"),
171+
LastModified = response.LastModified,
172+
CreationTime = response.LastModified,
167173
MimeType = response.Headers.ContentType,
168-
Length = response.Headers.ContentLength,
169-
Container = StorageOptions.Bucket
174+
Length = response.Headers.ContentLength
170175
};
171176

172177
await localFile.CopyFromStreamAsync(await StorageClient.GetObjectStreamAsync(StorageOptions.Bucket, options.FullPath, null,
@@ -249,8 +254,11 @@ protected override async Task<Result<BlobMetadata>> GetBlobMetadataInternalAsync
249254

250255
var metadata = new BlobMetadata
251256
{
252-
Name = options.FullPath,
257+
Name = options.FileName,
258+
Container = StorageOptions.Bucket,
253259
Uri = new Uri($"https://s3.amazonaws.com/{StorageOptions.Bucket}/{options.FullPath}"),
260+
LastModified = objectMetaResponse.LastModified,
261+
CreationTime = objectMetaResponse.LastModified,
254262
MimeType = objectMetaResponse.Headers.ContentType,
255263
Length = objectMetaResponse.Headers.ContentLength
256264
};

ManagedCode.Storage.Azure/AzureStorage.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ protected override async Task<Result<BlobMetadata>> GetBlobMetadataInternalAsync
269269
Uri = blobClient.Uri,
270270
Container = blobClient.BlobContainerName,
271271
Length = properties.Value.ContentLength,
272+
CreationTime = properties.Value.CreatedOn,
273+
LastModified = properties.Value.LastModified,
272274
Metadata = properties.Value.Metadata.ToDictionary(k => k.Key, v => v.Value),
273275
MimeType = properties.Value.ContentType
274276
});

ManagedCode.Storage.AzureDataLake/AzureDataLakeStorage.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ protected override async Task<Result<BlobMetadata>> GetBlobMetadataInternalAsync
233233
Uri = fileClient.Uri,
234234
Container = fileClient.FileSystemName,
235235
Length = properties.Value.ContentLength,
236+
CreationTime = properties.Value.CreatedOn,
237+
LastModified = properties.Value.LastModified,
236238
Metadata = properties.Value.Metadata.ToDictionary(k => k.Key, v => v.Value),
237239
MimeType = properties.Value.ContentType
238240
});

ManagedCode.Storage.Core/Models/BlobMetadata.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class BlobMetadata
99
public string Name { get; set; } = null!;
1010
public Uri? Uri { get; set; }
1111
public Dictionary<string, string>? Metadata { get; set; }
12+
public DateTimeOffset LastModified { get; set; }
13+
public DateTimeOffset CreationTime { get; set; }
1214
public string? Container { get; set; }
1315
public string? MimeType { get; set; }
1416
public long Length { get; set; }

ManagedCode.Storage.FileSystem/FileSystemStorage.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ protected override async Task<Result<BlobMetadata>> GetBlobMetadataInternalAsync
166166
Name = fileInfo.Name,
167167
Uri = new Uri(Path.Combine(_path, filePath)),
168168
MimeType = MimeHelper.GetMimeType(fileInfo.Extension),
169+
CreationTime = fileInfo.CreationTimeUtc,
170+
LastModified = fileInfo.LastWriteTimeUtc,
169171
Length = fileInfo.Length
170172
};
171173

ManagedCode.Storage.Gcp/GCPStorage.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,17 @@ public override IAsyncEnumerable<BlobMetadata> GetBlobMetadataListAsync(string?
5757

5858
{
5959
return StorageClient.ListObjectsAsync(StorageOptions.BucketOptions.Bucket, directory,
60-
new ListObjectsOptions { Projection = Projection.Full })
60+
new ListObjectsOptions {Projection = Projection.Full})
6161
.Select(
6262
x => new BlobMetadata
6363
{
6464
Name = x.Name,
6565
Uri = string.IsNullOrEmpty(x.MediaLink) ? null : new Uri(x.MediaLink),
6666
Container = x.Bucket,
67+
CreationTime = x.TimeCreated!.Value,
68+
LastModified = x.Updated!.Value,
6769
MimeType = x.ContentType,
68-
Length = (long)(x.Size ?? 0)
70+
Length = (long) (x.Size ?? 0)
6971
}
7072
);
7173
}
@@ -111,7 +113,7 @@ protected override async Task<Result> DeleteDirectoryInternalAsync(string direct
111113
{
112114
await EnsureContainerExist();
113115
var blobs = StorageClient.ListObjectsAsync(StorageOptions.BucketOptions.Bucket, string.Empty,
114-
new ListObjectsOptions { Projection = Projection.Full })
116+
new ListObjectsOptions {Projection = Projection.Full})
115117
.Select(x => x);
116118

117119
await foreach (var blob in blobs.WithCancellation(cancellationToken))
@@ -135,6 +137,7 @@ protected override async Task<Result<BlobMetadata>> UploadInternalAsync(Stream s
135137
try
136138
{
137139
await EnsureContainerExist();
140+
138141
await StorageClient.UploadObjectAsync(StorageOptions.BucketOptions.Bucket, options.FullPath, options.MimeType, stream, null,
139142
cancellationToken);
140143

@@ -218,8 +221,10 @@ protected override async Task<Result<BlobMetadata>> GetBlobMetadataInternalAsync
218221
Name = obj.Name,
219222
Uri = string.IsNullOrEmpty(obj.MediaLink) ? null : new Uri(obj.MediaLink),
220223
Container = obj.Bucket,
224+
CreationTime = obj.TimeCreated!.Value,
225+
LastModified = obj.Updated!.Value,
221226
MimeType = obj.ContentType,
222-
Length = (long)(obj.Size ?? 0)
227+
Length = (long) (obj.Size ?? 0)
223228
});
224229
}
225230
catch (Exception ex)

0 commit comments

Comments
 (0)