Added content type

This commit is contained in:
Dominic Villemure
2024-06-30 23:40:57 -04:00
parent 041b8178ac
commit 9481840244
7 changed files with 25 additions and 9 deletions

View File

@@ -25,8 +25,9 @@ public class AzureBlobStorageService : IAzureBlobStorageService
/// <param name="blobName">The blob name (path within the container, include the file name).</param>
/// <param name="containerName">The name of the container where the file is stored.</param>
/// <param name="fileStream">The stream.</param>
/// <param name="contentType">The content type.</param>
/// <returns></returns>
public async Task<string> UploadFileAsync(string containerName, string blobName, Stream fileStream)
public async Task<string> UploadFileAsync(string containerName, string blobName, Stream fileStream, string contentType)
{
// Get a reference to a container
var containerClient = _blobServiceClient.GetBlobContainerClient(containerName);
@@ -36,9 +37,18 @@ public class AzureBlobStorageService : IAzureBlobStorageService
// Get a reference to a blob
var blobClient = containerClient.GetBlobClient(blobName);
// Define the BlobHttpHeaders to include the content type
var blobHttpHeaders = new BlobHttpHeaders
{
ContentType = contentType
};
// Upload the file
await blobClient.UploadAsync(fileStream, true);
await blobClient.UploadAsync(fileStream, new BlobUploadOptions
{
HttpHeaders = blobHttpHeaders
});
// Return the URI of the uploaded blob
return blobClient.Uri.ToString();