Force contentType from the headers to be .png, .jpeg or .jpg

This commit is contained in:
Dominic Villemure
2024-07-10 01:38:27 -04:00
parent 0c549fd262
commit d2c6209954
8 changed files with 73 additions and 34 deletions

View File

@@ -1,6 +1,3 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Azure;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
@@ -16,7 +13,6 @@ public class AzureBlobStorageService : IAzureBlobStorageService
private readonly ILogger<AzureBlobStorageService> _logger;
private readonly long _maxUploadSize = 10 * 1024 * 1024; // 10 MB in bytes
public AzureBlobStorageService(IConfiguration configuration, ILogger<AzureBlobStorageService> logger)
{
_logger = logger;
@@ -47,6 +43,13 @@ public class AzureBlobStorageService : IAzureBlobStorageService
throw new InvalidOperationException($"Blob storage: File size exceeds the maximum allowed size of {_maxUploadSize} bytes.");
}
// Validate content type
if (!ContentTypes.IsAllowed(contentType))
{
_logger.LogInformation($"Blob storage: Unsupported file type {contentType}. Only PNG and JPEG are allowed.");
throw new InvalidOperationException("Unsupported file type. Only PNG and JPEG are allowed.");
}
try
{
// Get a reference to a container