https://github.com/wk-j/custom-model-binder
https://github.com/wk-j/custom-model-binder
Last synced: 26 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/wk-j/custom-model-binder
- Owner: wk-j
- Created: 2024-08-12T09:43:32.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-08-12T10:55:46.000Z (9 months ago)
- Last Synced: 2025-02-08T18:14:51.029Z (3 months ago)
- Language: C#
- Size: 31.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MyWeb API Project
A .NET 8.0 Web API project with file uploads and client API generation.
## Features
- File Upload API with metadata
- Custom Model Binding for file uploads
- Swagger/OpenAPI integration
- Client API code generation## Quick Start
1. Run API: `cd src/MyWeb && dotnet run`
2. Generate client: `dotnet build src/MyWeb && dotnet run --project src/AppGenerator`## API Endpoints
- POST `/Upload`: File upload with metadata## Custom Model Binding
This project uses a custom `FileUploadModelBinder` to handle file uploads with additional metadata. Here's how it works:
1. The `FileUploadModelBinder` implements `IModelBinder` interface.
2. It binds incoming multipart form data to the `FileUploadModel` class.
3. The binder extracts:
- File content
- Description (string)
- Category (string)
- Upload date (DateTime)
- Metadata (Dictionary)
4. It handles potential JSON deserialization for the metadata field.
5. The binder allows for flexible and type-safe handling of complex file upload requests.This approach provides a clean separation of concerns and makes it easy to handle complex file upload scenarios with additional metadata.