github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/docs/extensions/s3zip/examples/minio-go/main.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"io"
     6  	"log"
     7  	"os"
     8  
     9  	"github.com/minio/minio-go/v7"
    10  	"github.com/minio/minio-go/v7/pkg/credentials"
    11  )
    12  
    13  func main() {
    14  	s3Client, err := minio.New("minio-server-address:9000", &minio.Options{
    15  		Creds: credentials.NewStaticV4("access-key", "secret-key", ""),
    16  	})
    17  	if err != nil {
    18  		log.Fatalln(err)
    19  	}
    20  
    21  	var opts minio.GetObjectOptions
    22  
    23  	// Add extract header to request:
    24  	opts.Set("x-minio-extract", "true")
    25  
    26  	// Download API.md from the archive
    27  	rd, err := s3Client.GetObject(context.Background(), "your-bucket", "path/to/file.zip/data.csv", opts)
    28  	if err != nil {
    29  		log.Fatalln(err)
    30  	}
    31  	_, err = io.Copy(os.Stdout, rd)
    32  	if err != nil {
    33  		log.Fatalln(err)
    34  	}
    35  }