MinIO Go client SDK for S3 compatible object storage
Go to file
2024-10-21 15:04:02 -07:00
.github/workflows update dependencies (#2010) 2024-10-12 02:34:47 -07:00
docs NEW API: GetObjectAttributes (#1921) 2024-01-08 11:18:53 -08:00
examples Update version to next release 2024-10-12 09:41:18 +00:00
pkg add = character to tag validation regex (#2008) 2024-10-12 02:35:31 -07:00
testcerts Increase default multipart size to 128MiB (#1112) 2019-05-28 15:24:59 -07:00
.gitignore feat(#1755): GetObject supports overriding response header values (#1756) 2023-01-18 21:05:12 +05:30
.golangci.yml fix: use seeker to avoid memory without multipart upload (#1699) 2022-09-28 01:20:31 -07:00
api_unit_test.go add Client.SetS3EnableDualstack (#1945) 2024-03-10 15:09:46 +01:00
api-bucket-cors.go API methods for bucket-level CORS configuration settings (#1987) 2024-07-30 23:35:48 -07:00
api-bucket-encryption.go simplify healthcheck implementation (#1555) 2021-09-21 11:34:34 -07:00
api-bucket-lifecycle.go Revert "Add header for lifecycle config expiry to ignore replication (#1999)" 2024-09-20 22:35:38 -07:00
api-bucket-notification.go remove sha256-simd support we do not need it anymore (#1958) 2024-04-25 13:25:37 -07:00
api-bucket-policy.go Add staticcheck (#1735) 2022-12-07 00:34:11 -08:00
api-bucket-replication.go run gofumpt -extra -w on all files (#1854) 2023-07-12 07:26:00 -07:00
api-bucket-tagging.go Add staticcheck (#1735) 2022-12-07 00:34:11 -08:00
api-bucket-versioning.go versioning: Add support for ExcludedPrefixes and ExcludeFolders (#1646) 2022-05-06 23:06:55 -07:00
api-compose-object_test.go run gofumpt -w on codebase 2022-04-13 12:02:29 -07:00
api-compose-object.go Keep all x-minio- headers as-is (#1970) 2024-06-10 08:48:10 -07:00
api-copy-object.go Add staticcheck (#1735) 2022-12-07 00:34:11 -08:00
api-datatypes.go add all the internal data type (#1849) 2023-07-10 16:05:11 -07:00
api-error-response_test.go Add staticcheck (#1735) 2022-12-07 00:34:11 -08:00
api-error-response.go look for extended error codes when error body is unavailable 2023-06-18 11:13:16 -07:00
api-get-object_test.go fix: latest linter issues (#1929) 2024-02-10 15:52:57 -08:00
api-get-object-acl.go acl: Fix GetObjectACL xml parsing (#1598) 2021-12-10 10:34:26 -08:00
api-get-object-attributes.go NEW API: GetObjectAttributes (#1921) 2024-01-08 11:18:53 -08:00
api-get-object-file.go fix: non md5 etags (#1952) 2024-04-19 15:31:54 +02:00
api-get-object.go return appropriate error type for generic handling (#1981) 2024-07-02 13:41:41 -07:00
api-get-options.go Allow passing custom get query params (#1905) 2023-12-05 14:08:50 -08:00
api-list.go run gofumpt -extra -w on all files (#1854) 2023-07-12 07:26:00 -07:00
api-object-legal-hold.go simplify healthcheck implementation (#1555) 2021-09-21 11:34:34 -07:00
api-object-lock.go simplify healthcheck implementation (#1555) 2021-09-21 11:34:34 -07:00
api-object-retention.go simplify healthcheck implementation (#1555) 2021-09-21 11:34:34 -07:00
api-object-tagging.go Add fields to tagging opts for replication (#1913) 2023-12-13 20:33:11 -08:00
api-presigned.go run gofumpt -extra -w on all files (#1854) 2023-07-12 07:26:00 -07:00
api-put-bucket.go run gofumpt -extra -w on all files (#1854) 2023-07-12 07:26:00 -07:00
api-put-object_test.go Add Checksum to PutObject (#2002) 2024-09-24 01:40:12 -07:00
api-put-object-common.go run gofumpt -extra -w on all files (#1854) 2023-07-12 07:26:00 -07:00
api-put-object-fan-out.go Fix fanout response unmarshalable error type (#1839) 2023-06-15 07:36:47 -07:00
api-put-object-file-context.go simplify healthcheck implementation (#1555) 2021-09-21 11:34:34 -07:00
api-put-object-multipart.go Add configurable auto-checksum (#1990) 2024-08-21 05:16:29 -07:00
api-put-object-streaming.go only retry multi-part upload as single-part upload on GCS endpoints (#2012) 2024-10-21 15:04:02 -07:00
api-put-object.go add missing ReplicationStatusReplicaEdge 2024-10-02 00:19:55 -07:00
api-putobject-snowball.go Add Checksum to PutObject (#2002) 2024-09-24 01:40:12 -07:00
api-remove.go Update api-remove.go (#1926) 2024-01-29 11:47:17 +01:00
api-restore.go restore: Accept http code 202 and 200 as valid response (#1621) 2022-02-09 09:36:53 -08:00
api-s3-datatypes.go Add configurable auto-checksum (#1990) 2024-08-21 05:16:29 -07:00
api-select.go Add staticcheck (#1735) 2022-12-07 00:34:11 -08:00
api-stat.go return appropriate error type for generic handling (#1981) 2024-07-02 13:41:41 -07:00
api.go Update version to next release 2024-10-12 09:41:18 +00:00
bucket-cache_test.go allow virtual host style for GetBucketLocation API, if requested (#1785) 2023-03-06 08:57:24 -08:00
bucket-cache.go run gofumpt -extra -w on all files (#1854) 2023-07-12 07:26:00 -07:00
checksum.go Add configurable auto-checksum (#1990) 2024-08-21 05:16:29 -07:00
CNAME Create CNAME 2020-08-02 16:57:50 -07:00
code_of_conduct.md upgrade golang-lint and fix the reported issues (#1329) 2020-07-06 06:41:25 -07:00
constants.go Revert "Add header for lifecycle config expiry to ignore replication (#1999)" 2024-09-20 22:35:38 -07:00
CONTRIBUTING.md remove EOLed support this library supports from go1.16 2021-12-07 15:45:15 -08:00
core_test.go Drop more seeding in tests (#1942) 2024-02-28 03:18:11 -08:00
core.go Add DisableContentSha256 to PutObjectPartOptions (#1988) 2024-08-05 08:29:11 -07:00
CREDITS remove sha256-simd support we do not need it anymore (#1958) 2024-04-25 13:25:37 -07:00
functional_tests.go add a non-TLS test (#2005) 2024-10-09 12:28:27 -07:00
get-options_test.go Allow passing custom get query params (#1905) 2023-12-05 14:08:50 -08:00
go.mod update dependencies (#2010) 2024-10-12 02:34:47 -07:00
go.sum update dependencies (#2010) 2024-10-12 02:34:47 -07:00
healthcheck_test.go fix: latest linter issues (#1929) 2024-02-10 15:52:57 -08:00
hook-reader.go re-implement ReaderAt implementation with race protection (#1673) 2022-07-06 12:57:11 -07:00
LICENSE Object storage library - first commit 2015-05-01 23:59:31 -07:00
MAINTAINERS.md Replace Minio with MinIO and minio.io with min.io (#1096) 2019-04-07 15:54:46 -07:00
Makefile add a non-TLS test (#2005) 2024-10-09 12:28:27 -07:00
NOTICE upgrade golang-lint and fix the reported issues (#1329) 2020-07-06 06:41:25 -07:00
post-policy.go Fixed #2000 - Add support for "starts-with" in user-metadata post policy condition. (#2001) 2024-09-19 06:01:34 -07:00
README.md Update remove bucket replication reference (#2006) 2024-10-14 08:17:43 -07:00
retry-continous.go run gofumpt -extra -w on all files (#1854) 2023-07-12 07:26:00 -07:00
retry.go Retry on internal HTTP context cancellations (#1998) 2024-09-05 04:00:20 -07:00
s3-endpoints.go Add ca-west-1 endpoint (#1971) 2024-06-24 23:12:36 -07:00
s3-error.go API methods for bucket-level CORS configuration settings (#1987) 2024-07-30 23:35:48 -07:00
test-utils_test.go Add staticcheck (#1735) 2022-12-07 00:34:11 -08:00
transport.go Add staticcheck (#1735) 2022-12-07 00:34:11 -08:00
utils_test.go fix: GCS endpoint validation to allow ports (#1985) 2024-07-15 15:39:40 -07:00
utils.go Keep all x-minio- headers as-is (#1970) 2024-06-10 08:48:10 -07:00

MinIO Go Client SDK for Amazon S3 Compatible Cloud Storage Slack Sourcegraph Apache V2 License

The MinIO Go Client SDK provides straightforward APIs to access any Amazon S3 compatible object storage.

This Quickstart Guide covers how to install the MinIO client SDK, connect to MinIO, and create a sample file uploader. For a complete list of APIs and examples, see the godoc documentation or Go Client API Reference.

These examples presume a working Go development environment and the MinIO mc command line tool.

Download from Github

From your project directory:

go get github.com/minio/minio-go/v7

Initialize a MinIO Client Object

The MinIO client requires the following parameters to connect to an Amazon S3 compatible object storage:

Parameter Description
endpoint URL to object storage service.
_minio.Options_ All the options such as credentials, custom transport etc.
package main

import (
	"log"

	"github.com/minio/minio-go/v7"
	"github.com/minio/minio-go/v7/pkg/credentials"
)

func main() {
	endpoint := "play.min.io"
	accessKeyID := "Q3AM3UQ867SPQQA43P2F"
	secretAccessKey := "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
	useSSL := true

	// Initialize minio client object.
	minioClient, err := minio.New(endpoint, &minio.Options{
		Creds:  credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
		Secure: useSSL,
	})
	if err != nil {
		log.Fatalln(err)
	}

	log.Printf("%#v\n", minioClient) // minioClient is now set up
}

Example - File Uploader

This sample code connects to an object storage server, creates a bucket, and uploads a file to the bucket. It uses the MinIO play server, a public MinIO cluster located at https://play.min.io.

The play server runs the latest stable version of MinIO and may be used for testing and development. The access credentials shown in this example are open to the public and all data uploaded to play should be considered public and non-protected.

FileUploader.go

This example does the following:

  • Connects to the MinIO play server using the provided credentials.
  • Creates a bucket named testbucket.
  • Uploads a file named testdata from /tmp.
  • Verifies the file was created using mc ls.
// FileUploader.go MinIO example
package main

import (
	"context"
	"log"

	"github.com/minio/minio-go/v7"
	"github.com/minio/minio-go/v7/pkg/credentials"
)

func main() {
	ctx := context.Background()
	endpoint := "play.min.io"
	accessKeyID := "Q3AM3UQ867SPQQA43P2F"
	secretAccessKey := "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
	useSSL := true

	// Initialize minio client object.
	minioClient, err := minio.New(endpoint, &minio.Options{
		Creds:  credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
		Secure: useSSL,
	})
	if err != nil {
		log.Fatalln(err)
	}

	// Make a new bucket called testbucket.
	bucketName := "testbucket"
	location := "us-east-1"

	err = minioClient.MakeBucket(ctx, bucketName, minio.MakeBucketOptions{Region: location})
	if err != nil {
		// Check to see if we already own this bucket (which happens if you run this twice)
		exists, errBucketExists := minioClient.BucketExists(ctx, bucketName)
		if errBucketExists == nil && exists {
			log.Printf("We already own %s\n", bucketName)
		} else {
			log.Fatalln(err)
		}
	} else {
		log.Printf("Successfully created %s\n", bucketName)
	}

	// Upload the test file
	// Change the value of filePath if the file is in another location
	objectName := "testdata"
	filePath := "/tmp/testdata"
	contentType := "application/octet-stream"

	// Upload the test file with FPutObject
	info, err := minioClient.FPutObject(ctx, bucketName, objectName, filePath, minio.PutObjectOptions{ContentType: contentType})
	if err != nil {
		log.Fatalln(err)
	}

	log.Printf("Successfully uploaded %s of size %d\n", objectName, info.Size)
}

1. Create a test file containing data:

You can do this with dd on Linux or macOS systems:

dd if=/dev/urandom of=/tmp/testdata bs=2048 count=10

or fsutil on Windows:

fsutil file createnew "C:\Users\<username>\Desktop\sample.txt" 20480

2. Run FileUploader with the following commands:

go mod init example/FileUploader
go get github.com/minio/minio-go/v7
go get github.com/minio/minio-go/v7/pkg/credentials
go run FileUploader.go

The output resembles the following:

2023/11/01 14:27:55 Successfully created testbucket
2023/11/01 14:27:55 Successfully uploaded testdata of size 20480

3. Verify the Uploaded File With mc ls:

mc ls play/testbucket
[2023-11-01 14:27:55 UTC]  20KiB STANDARD TestDataFile

API Reference

The full API Reference is available here.

API Reference : Bucket Operations

API Reference : Bucket policy Operations

API Reference : Bucket notification Operations

API Reference : File Object Operations

API Reference : Object Operations

API Reference : Presigned Operations

API Reference : Client custom settings

Full Examples

Full Examples : Bucket Operations

Full Examples : Bucket policy Operations

Full Examples : Bucket lifecycle Operations

Full Examples : Bucket encryption Operations

Full Examples : Bucket replication Operations

Full Examples : Bucket notification Operations

Full Examples : File Object Operations

Full Examples : Object Operations

Full Examples : Encrypted Object Operations

Full Examples : Presigned Operations

Explore Further

Contribute

Contributors Guide

License

This SDK is distributed under the Apache License, Version 2.0, see LICENSE and NOTICE for more information.