Add Method for uploading Instruction Image to Controller and put ValidateAntiForgeryKey instead of AutoValidateAntiForgeryKey
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
|
||||
// POST: /UploadImage
|
||||
[HttpPost("UploadImage")]
|
||||
[AutoValidateAntiforgeryToken]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> UploadImage(Guid recipeId, IFormFile? mediaFile)
|
||||
{
|
||||
if (mediaFile is null)
|
||||
@@ -42,7 +42,7 @@
|
||||
}
|
||||
|
||||
[HttpPost("ReplaceInstructionImage")]
|
||||
[AutoValidateAntiforgeryToken]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> ReplaceInstructionImage(Guid instructionId, Guid mediaFileIdToReplace, IFormFile? newPhoto)
|
||||
{
|
||||
if (newPhoto is null)
|
||||
@@ -67,5 +67,26 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("Recipe/{recipeId}/Instruction/{instructionId}/UploadImage")]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> UploadInstructionImage(Guid recipeId, Guid instructionId, IFormFile? photo)
|
||||
{
|
||||
if (photo == null)
|
||||
{
|
||||
return BadRequest("Photo is required.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await _mediaFileRepository.UploadInstructionImageAsync(instructionId, photo);
|
||||
|
||||
return RedirectToAction("GetInstructions", "Instruction", new { recipeId });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Internal server error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user