Merged PR 90: Added content type into main
Added content type
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
public static class CommonFileNames
|
||||
{
|
||||
public static string ProfilePicture = "profilePicture";
|
||||
public static string BannerPicture = "bannerPicture";
|
||||
public static string WebsiteIcon = "websiteIcon";
|
||||
public static string ProfilePicture = "profilePicture.png";
|
||||
public static string BannerPicture = "bannerPicture.png";
|
||||
public static string WebsiteIcon = "websiteIcon.png";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Hutopy.Application.AzureBlobStorage.Constants;
|
||||
|
||||
public static class ContentTypes
|
||||
{
|
||||
public static string ImagePng = "image/png";
|
||||
}
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
public interface IAzureBlobStorageService
|
||||
{
|
||||
Task<string> UploadFileAsync(string containerName, string blobName, Stream fileStream);
|
||||
Task<string> UploadFileAsync(string containerName, string blobName, Stream fileStream, string contentType);
|
||||
Task<MemoryStream> DownloadFileAsync(string containerName, string blobName);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class UploadBannerPictureCommandHandler(IIdentityService identityService,
|
||||
|
||||
var blobName = $"{currentUserId}/{SubDirectoryNames.Profile}/{CommonFileNames.BannerPicture}";
|
||||
|
||||
var url = await azureBlobStorageService.UploadFileAsync(ContainerNames.Users, blobName, request.BannerPicture);
|
||||
var url = await azureBlobStorageService.UploadFileAsync(ContainerNames.Users, blobName, request.BannerPicture, ContentTypes.ImagePng);
|
||||
|
||||
await identityService.UpdateCurrentUserBannerPictureUrlAsync(url);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public class UploadProfilePictureCommandHandler(IIdentityService identityService
|
||||
|
||||
var blobName = $"{currentUserId}/{SubDirectoryNames.Profile}/{CommonFileNames.ProfilePicture}";
|
||||
|
||||
var url = await azureBlobStorageService.UploadFileAsync(ContainerNames.Users, blobName, request.ProfilePicture);
|
||||
var url = await azureBlobStorageService.UploadFileAsync(ContainerNames.Users, blobName, request.ProfilePicture, ContentTypes.ImagePng);
|
||||
|
||||
await identityService.UpdateCurrentUserProfilePictureUrlAsync(url);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public class UploadWebsiteIconCommandHandler(IIdentityService identityService, I
|
||||
|
||||
var blobName = $"{currentUserId}/{SubDirectoryNames.Profile}/{CommonFileNames.WebsiteIcon}";
|
||||
|
||||
var url = await azureBlobStorageService.UploadFileAsync(ContainerNames.Users, blobName, request.WebsiteIcon);
|
||||
var url = await azureBlobStorageService.UploadFileAsync(ContainerNames.Users, blobName, request.WebsiteIcon, ContentTypes.ImagePng);
|
||||
|
||||
await identityService.UpdateCurrentUserWebsiteIconUrlAsync(url);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user