Skip to content

Commit

Permalink
add content-type for appendblob
Browse files Browse the repository at this point in the history
  • Loading branch information
bethanyj28 committed Feb 5, 2024
1 parent be3ebf2 commit 5135617
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/Sdk/WebApi/WebApi/ResultsHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,34 @@ private async Task UploadBlockFileAsync(string url, string blobStorageType, File
}
}

private async Task CreateAppendFileAsync(string url, string blobStorageType, CancellationToken cancellationToken)
private async Task CreateAppendFileAsync(string url, string blobStorageType, CancellationToken cancellationToken, Dictionary<string, string> customHeaders = null)
{
if (m_useSdk && blobStorageType == BlobStorageTypes.AzureBlobStorage)
{
var appendBlobClient = GetAppendBlobClient(url);
var httpHeaders = new BlobHttpHeaders();
if (customHeaders != null)
{
foreach (var header in customHeaders)
{
switch (header.Key)
{
case Constants.ContentTypeHeader:
httpHeaders.ContentType = header.Value;
break;
}
}
}
try
{
await appendBlobClient.CreateAsync(cancellationToken: cancellationToken);
await appendBlobClient.CreateAsync(new AppendBlobCreateOptions()
{
HttpHeaders = httpHeaders,
Conditions = new AppendBlobRequestConditions
{
IfNoneMatch = new ETag("*")
}
}, cancellationToken: cancellationToken);
}
catch (RequestFailedException e)
{
Expand All @@ -312,6 +332,13 @@ private async Task CreateAppendFileAsync(string url, string blobStorageType, Can
request.Content.Headers.Add(Constants.AzureBlobTypeHeader, Constants.AzureAppendBlob);
request.Content.Headers.Add("Content-Length", "0");
}
if (customHeaders != null)
{
foreach (var header in customHeaders)
{
request.Content.Headers.Add(header.Key, header.Value);
}
};

using (var response = await SendAsync(request, HttpCompletionOption.ResponseHeadersRead, userState: null, cancellationToken))
{
Expand Down Expand Up @@ -410,7 +437,7 @@ private async Task UploadLogFile(string file, bool finalize, bool firstBlock, st
// Create the Append blob
if (firstBlock)
{
await CreateAppendFileAsync(sasUrl, blobStorageType, cancellationToken);
await CreateAppendFileAsync(sasUrl, blobStorageType, cancellationToken, customHeaders);
}

// Upload content
Expand Down

0 comments on commit 5135617

Please sign in to comment.