mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 11:44:56 +00:00
3.3 KiB
3.3 KiB
description
| description |
|---|
| Controller for uploading and downloading media files. |
MediaController
Controller Description
- Route:
api/media - Authorize: Requires authenticated user with roles "User" or "Admin" (
[Authorize(Roles = "User,Admin")]).
Endpoints
Upload
- Description: Uploads a media file with associated metadata.
- Route:
[POST] api/media/upload - HTTP Method:
POST - Request:
-
Content-Type:
multipart/form-data -
Request Body:
MediaUploadRequestobject with the following structure:{ "fromFile": "IFormFile", "type": "MediaType", "mimeType": "string", "encryptedKey": "string" } -
Constraints: File size limit of 20 MB.
-
- Responses:
-
200 OK: Returns the upload result.
"string" // Media ID or similar result -
400 Bad Request:
- If model validation fails.
- If no file is uploaded:
"No file uploaded" - If file exceeds 20 MB:
"File is too large" - If MIME type is missing:
"Missing MIME type" - If operation is invalid:
"string"
-
403 Forbidden: If user lacks authorization.
"string" -
500 Internal Server Error: Indicates an unexpected error.
"Internal server error"
-
Download
- Description: Downloads a media file by its ID.
- Route:
[GET] api/media/download/{id} - HTTP Method:
GET - Request:
- Path Parameter:
id(Guid, required): ID of the media file.
- Path Parameter:
- Responses:
-
200 OK: Returns the media file as a stream.
- Content-Type: Matches
MimeTypeof the media. - Content-Disposition: Includes
filenamefromFileName.
- Content-Type: Matches
-
403 Forbidden: If user lacks access.
- No body.
-
404 Not Found: If media is not found.
"Media not found" -
500 Internal Server Error: Indicates an unexpected error.
"Internal server error"
-
Data Models
MediaUploadRequest
-
Description: Model for media upload request data.
-
Structure:
{ "fromFile": "IFormFile", "type": "MediaType", "mimeType": "string", "encryptedKey": "string" }
Error Handling
- Invalid User ID: Handled by
ICurrentUserService, aborts if invalid. - Invalid Operations: Returns
400 Bad RequestforInvalidOperationException. - Unauthorized Access: Returns
403 ForbiddenforUnauthorizedAccessException. - Resource Not Found: Returns
404 Not FoundforKeyNotFoundException. - Unexpected Errors: Caught and returned as
500 Internal Server Error.
Logging
- Logs warnings for
UnauthorizedAccessException,InvalidOperationException, andKeyNotFoundException. - Logs information for successful file uploads.
- Logs errors for unexpected exceptions during upload and download.