Skip to content

Commit

Permalink
Fix OnSaveAsync similarly
Browse files Browse the repository at this point in the history
  • Loading branch information
joelverhagen committed Aug 1, 2024
1 parent 8b42d83 commit 8ca9e56
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/Catalog/Persistence/AzureStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,7 @@ protected override async Task OnCopyAsync(
// Set destination properties if provided
if (destinationProperties?.Count > 0)
{
// Use the existing properties of the destination blob to ensure that all properties are copied
// Source: https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-properties-metadata#set-and-retrieve-properties
BlobProperties properties = await destinationBlockBlob.GetPropertiesAsync();
var headers = new BlobHttpHeaders
{
CacheControl = properties.CacheControl,
ContentType = properties.ContentType,
ContentDisposition = properties.ContentDisposition,
ContentEncoding = properties.ContentEncoding,
ContentLanguage = properties.ContentLanguage,
ContentHash = properties.ContentHash,
};
BlobHttpHeaders headers = await GetExistingHttpHeadersAsync(destinationBlockBlob);

// The copy statement copied all properties from the source blob to the destination blob; however,
// there may be required properties on destination blob, all of which may have not already existed
Expand All @@ -284,16 +273,28 @@ protected override async Task OnCopyAsync(
}
}

private static async Task<BlobHttpHeaders> GetExistingHttpHeadersAsync(BlockBlobClient blob)
{
// Source: https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-properties-metadata#set-and-retrieve-properties
BlobProperties properties = await blob.GetPropertiesAsync();

return new BlobHttpHeaders
{
CacheControl = properties.CacheControl,
ContentType = properties.ContentType,
ContentDisposition = properties.ContentDisposition,
ContentEncoding = properties.ContentEncoding,
ContentLanguage = properties.ContentLanguage,
ContentHash = properties.ContentHash,
};
}

protected override async Task OnSaveAsync(Uri resourceUri, StorageContent content, CancellationToken cancellationToken)
{
string blobName = GetName(resourceUri);
BlockBlobClient blockBlobClient = GetBlockBlobReference(blobName);

var headers = new BlobHttpHeaders
{
ContentType = content.ContentType,
CacheControl = content.CacheControl
};
BlobHttpHeaders headers = await GetExistingHttpHeadersAsync(blockBlobClient);

if (_compressContent)
{
Expand Down

0 comments on commit 8ca9e56

Please sign in to comment.