MinIO
MinIO File Upload & Download Example
This example demonstrates a simple Go Fiber application that includes modules for uploading both single and multiple files, as well as downloading files from MinIO. Each module provides REST API endpoints for file upload and retrieval, serving as a foundation for applications requiring file storage and access.
Prerequisites
Ensure you have the following installed:
- Go: (version 1.27 or higher) installed
- Docker and Docker Compose: for running a local MinIO instance
- Git
Project Structure
single/main.go: Example for uploading and downloading a single file to/from MinIO.multiple/main.go: Example for uploading multiple files to MinIO and downloading files from MinIO.go.mod: Go module file managing project dependencies.
Getting Started
1. Clone the Repository
Clone the repository and navigate to the example directory:
git clone https://github.com/gofiber/recipes.git
cd recipes/minio2. Start MinIO with Docker Compose
A docker-compose.yml is provided for running a local MinIO instance:
docker compose up -dCheck the image first. The compose file uses
minio/minio:latest. In November 2026 Docker Hub answeredpull access denied for minio/minio, repository does not exist or may require 'docker login'for that name, sodocker compose upfails to pull it (quay.io/minio/minio:latestansweredunauthorized). Setimage:indocker-compose.ymlto a MinIO image you have access to, or skip Docker and point the recipe at any S3-compatible server or an existing MinIO withFIBER_MINIO_ENDPOINT,FIBER_MINIO_ACCESS_KEYandFIBER_MINIO_SECRET_KEY. The Go code only needs an S3 API endpoint, not MinIO specifically.
This starts MinIO on port 9000 (API) and 9001 (web console). Access the console at http://localhost:9001 with credentials minioadmin / minioadmin.
To stop MinIO:
docker compose down3. Install Dependencies
Use Goβs module system to install dependencies:
go mod downloadRunning the Examples
Uploading and Downloading a Single File
Go to the
singledirectory:cd singleStart the application:
go run main.goUpload a file using
curlorPostman:curl -F "document=@/path/to/your/file" http://localhost:3000/uploadDownload the file by specifying its name in the request:
curl -O http://localhost:3000/file/<filename>
Uploading Multiple Files and Downloading Files
Go to the
multipledirectory:cd multipleStart the application:
go run main.goUpload multiple files using
curlorPostman:curl -F "documents=@/path/to/your/file1" -F "documents=@/path/to/your/file2" http://localhost:3000/uploadDownload a file by specifying its name in the request.
curl -O http://localhost:3000/file/<filename>
Code Overview
single/main.go
Defines routes to handle a single file upload and download.
Includes error handling for file validation, MinIO connection, and bucket management.
multiple/main.go
Handles uploading multiple files in a single request and allows for file downloads.
Validates each file and provides detailed responses for both successful and failed uploads.
Conclusion
This example offers a approach for managing file uploads and downloads with Go Fiber and MinIO. It can be expanded to support additional features, such as adding metadata, handling large files, or restricting access to files.