A simple and efficient file upload API built with Go and Gin framework, supporting both local storage and AWS S3.
- ✅ Local file upload with size limit (10MB)
- ✅ File download from local storage
- ✅ AWS S3 file upload
- ✅ RESTful API endpoints
- ✅ Multipart form data support
- Go 1.24.2 or higher
- AWS credentials (for S3 upload)
git clone https://github.com/bibashjaprel/go-file-uploader.git
cd go-file-uploader
go mod downloadThe application uses environment variables for AWS configuration. You can set these in two ways:
-
Using a
.envfile (recommended for development):cp .env.example .env
Then edit
.envwith your actual values:AWS_REGION=us-east-1 AWS_BUCKET_NAME=your-actual-bucket-name -
Using system environment variables:
export AWS_REGION=us-east-1 export AWS_BUCKET_NAME=your-actual-bucket-name export AWS_ACCESS_KEY_ID=your-access-key export AWS_SECRET_ACCESS_KEY=your-secret-key
AWS credentials can be configured in multiple ways (in order of precedence):
- Environment variables:
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY - AWS credentials file:
~/.aws/credentials - IAM role (when running on AWS infrastructure)
For more information, see the AWS SDK for Go configuration guide.
Run the server:
go run main.goThe server will start at http://localhost:8080
Upload File
POST /upload
Content-Type: multipart/form-data
curl -X POST http://localhost:8080/upload \
-F "file=@/path/to/your/file"Download File
GET /uploads/:filename
curl http://localhost:8080/uploads/example.txtUpload to S3
POST /s3/upload
Content-Type: multipart/form-data
curl -X POST http://localhost:8080/s3/upload \
-F "file=@/path/to/your/file"go-file-uploader/
├── main.go # Main application entry point
├── localstorage/ # Local file storage handlers
│ └── basic.go
├── s3storage/ # AWS S3 storage handlers
│ └── basic.go
├── go.mod # Go module definition
└── README.md
- Multiple file upload
- Streaming for large files
- Retry & circuit breaker mechanism
- Rate limiting and MIME type filtering
- Background file processing
- File compression
- Authentication and authorization