test
#123 A lightweight file management service built with .NET 9, designed for internal use with minimal resource consumption.
- File upload/download/delete with metadata storage
- JWT-based authentication with fixed token
- MongoDB for metadata storage
- Local disk storage for files
- Minimal resource usage
- Fast startup and simple deployment
- .NET 9 SDK
- MongoDB instance
Update appsettings.json with your MongoDB connection string:
{
"Mongo": {
"ConnectionString": "mongodb://localhost:27017",
"DatabaseName": "FileServiceDb"
},
"Jwt": {
"Key": "SUPER_SECRET_KEY_123456789",
"Issuer": "InternalSystem",
"Audience": "InternalServices",
"ExpireMinutes": 43200
}
}- Install dependencies:
dotnet restore - Start MongoDB (if running locally)
- Run the application:
dotnet run - Navigate to
https://localhost:5001/swaggerfor API documentation
Make a POST request to /api/auth/token to get your JWT token:
curl -X POST https://localhost:5001/api/auth/tokenAll file operations require authentication. Include the JWT token in the Authorization header:
Authorization: Bearer {your-token-here}
POST /api/auth/token- Get JWT tokenPOST /api/files/upload- Upload a fileGET /api/files/{id}- Download a fileDELETE /api/files/{id}- Delete a fileGET /api/files/meta/{id}- Get file metadataGET /health- Health check
Uploaded files are stored in the following structure:
/uploads/{serviceName}/{yyyy}/{MM}/{dd}/{guid.ext}
For example:
/uploads/OrderService/2026/04/28/abc123.png
- Images:
.jpg,.jpeg,.png - Documents:
.pdf,.docx,.xlsx - Archives:
.zip
Maximum file size: 20MB
Build and run with Docker:
# Build the image
docker build -t file-service .
# Run the container (ensure MongoDB is accessible)
docker run -p 8080:80 -e Mongo__ConnectionString="mongodb://your-mongo-host:27017" file-service