Skip to content

Latest commit

 

History

History

minio

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

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.22 or higher) installed
  • minio: MinIO running on your local machine or a remote server
  • 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/minio

2. Install Dependencies

Use Go’s module system to install dependencies:

go mod download

Running the Examples

Uploading and Downloading a Single File

  1. Go to the single directory:

    cd single
  2. Start the application:

    go run main.go
  3. Upload a file using curl or Postman:

    curl -F "document=@/path/to/your/file" http://localhost:3000/upload
  4. Download the file by specifying its name in the request:

    curl -O http://localhost:3000/file/<filename>

Uploading Multiple Files and Downloading Files

  1. Go to the multiple directory:

    cd multiple
  2. Start the application:

    go run main.go
  3. Upload multiple files using curl or Postman:

    curl -F "documents=@/path/to/your/file1" -F "documents=@/path/to/your/file2" http://localhost:3000/upload
  4. Download 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.

References