title | keywords | |||
---|---|---|---|---|
MinIO |
|
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.
Ensure you have the following installed:
- Go: (version 1.22 or higher) installed
- minio: MinIO running on your local machine or a remote server
- Git
-
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.
Clone the repository and navigate to the example directory:
git clone https://github.com/gofiber/recipes.git
cd recipes/minio
Use Go’s module system to install dependencies:
go mod download
-
Go to the
single
directory:cd single
-
Start the application:
go run main.go
-
Upload a file using
curl
orPostman
:curl -F "document=@/path/to/your/file" http://localhost:3000/upload
-
Download the file by specifying its name in the request:
curl -O http://localhost:3000/file/<filename>
-
Go to the
multiple
directory:cd multiple
-
Start the application:
go run main.go
-
Upload multiple files using
curl
orPostman
:curl -F "documents=@/path/to/your/file1" -F "documents=@/path/to/your/file2" http://localhost:3000/upload
-
Download a file by specifying its name in the request.
curl -O http://localhost:3000/file/<filename>
-
Defines routes to handle a single file upload and download.
-
Includes error handling for file validation, MinIO connection, and bucket management.
-
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.
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.