ImageController

Namespace: Commissiestrijd.Controllers
Assembly: backend.dll

Controller for handling image retrieval. This controller allows users to retrieve images by filename. It checks if the user is an admin before allowing access to the images. The images are stored in the "submittedimages" directory within the current working directory. The images are served with the appropriate MIME type based on their file extension. If the image does not exist, a 404 Not Found response is returned.

[Authorize]
[ApiController]
[Route("[controller]")]
public class ImageController : Controller, IActionFilter, IAsyncActionFilter, IFilterMetadata, IDisposable

Inheritance

objectControllerBaseControllerImageController


Implements

IActionFilter, IAsyncActionFilter, IFilterMetadata,

IDisposable

Constructors


ImageController(ILogger<ImageController>)

Constructor for the ImageController. Initializes the controller with the provided database context and logger. This constructor is used to set up the necessary dependencies for the controller, allowing it to access submitted task data and log information or errors during operations.

public ImageController(ILogger<ImageController> logger)

Parameters

NameType
loggerILogger<ImageController>

Methods


GetImage(string)

Retrieves an image by its filename. This method checks if the user is an admin before allowing access to the image. The image is expected to be stored in the "submittedimages" directory within the current working directory. If the image exists, it is returned with the appropriate MIME type based on its file extension. If the image does not exist, a 404 Not Found response is returned.

[HttpGet("GetImage/{filename}")]
[SwaggerOperation(null, null, Summary = "Get Image", Description = "This endpoint retrieves an image by its filename.")]
[SwaggerResponse(200, "Returns the image file with the appropriate MIME type.", null)]
[ProducesResponseType(typeof(FileResult), 200)]
[SwaggerResponse(401, "Unauthorized if the user is not an admin.", null)]
[SwaggerResponse(404, "NotFound if the image file does not exist.", null)]
[SwaggerResponse(500, "Internal Server Error if an error occurs while processing the request.", null)]
public Task<IActionResult> GetImage(string filename)

Parameters

NameTypeDescription
filenamestringThe name of the image file to retrieve.

Returns

TypeDescription
TaskAn IActionResult containing the image file or a NotFound result if the image does not exist.