Change some things

This commit is contained in:
franc
2025-05-07 08:55:40 +02:00
parent 070df12049
commit 7bf43b1855
@@ -74,11 +74,13 @@
public async Task UploadRecipeMediaAsync(Guid recipeId, IFormFile mediaFile)
{
if (mediaFile == null)
if (mediaFile == null || mediaFile.Length == 0)
{
throw new ArgumentNullException(nameof(mediaFile));
return;
}
try
{
var recipe = await _recipeRepository.GetRecipeAsync(recipeId);
var isImage = mediaFile.ContentType.StartsWith("image/");
@@ -114,6 +116,11 @@
_context.MediaFiles.Add(newMedia);
await _context.SaveChangesAsync();
}
catch (Exception ex)
{
throw new InvalidOperationException("An error occurred while uploading the media file.", ex);
}
}
private async Task RemoveExistingMediaAsync(Recipe recipe, string mediaTypePrefix)
{