| 1 |
//go:build example |
| 2 |
// +build example |
| 3 |
|
| 4 |
/* |
| 5 |
* MinIO Go Library for Amazon S3 Compatible Cloud Storage |
| 6 |
* Copyright 2023 MinIO, Inc. |
| 7 |
* |
| 8 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
* you may not use this file except in compliance with the License. |
| 10 |
* You may obtain a copy of the License at |
| 11 |
* |
| 12 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
* |
| 14 |
* Unless required by applicable law or agreed to in writing, software |
| 15 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
* See the License for the specific language governing permissions and |
| 18 |
* limitations under the License. |
| 19 |
*/ |
| 20 |
|
| 21 |
package main |
| 22 |
|
| 23 |
import ( |
| 24 |
"context" |
| 25 |
"fmt" |
| 26 |
"io" |
| 27 |
"log" |
| 28 |
"os" |
| 29 |
|
| 30 |
"github.com/minio/minio-go/v7" |
| 31 |
"github.com/minio/minio-go/v7/pkg/credentials" |
| 32 |
"github.com/minio/minio-go/v7/pkg/encrypt" |
| 33 |
) |
| 34 |
|
| 35 |
func main() { |
| 36 |
const ( |
| 37 |
// Note: These constants are dummy values, |
| 38 |
// please replace them with values for your setup. |
| 39 |
YOURACCESSKEYID = "Q3AM3UQ867SPQQA43P2F" |
| 40 |
YOURSECRETACCESSKEY = "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG" |
| 41 |
YOURENDPOINT = "play.min.io" |
| 42 |
YOURBUCKET = "mybucket" // 'mc mb play/mybucket' if it does not exist. |
| 43 |
) |
| 44 |
|
| 45 |
// Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access. |
| 46 |
// This boolean value is the last argument for New(). |
| 47 |
|
| 48 |
// New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically |
| 49 |
// determined based on the Endpoint value. |
| 50 |
minioClient, err := minio.New(YOURENDPOINT, &minio.Options{ |
| 51 |
Creds: credentials.NewStaticV4(YOURACCESSKEYID, YOURSECRETACCESSKEY, ""), |
| 52 |
Secure: true, |
| 53 |
}) |
| 54 |
if err != nil { |
| 55 |
log.Fatalln(err) |
| 56 |
} |
| 57 |
|
| 58 |
// Enable tracing. |
| 59 |
minioClient.TraceOn(os.Stdout) |
| 60 |
|
| 61 |
filePath := "my-testfile" // Specify a local file that we will upload |
| 62 |
|
| 63 |
// Open a local file that we will upload |
| 64 |
file, err := os.Open(filePath) |
| 65 |
if err != nil { |
| 66 |
log.Fatalln(err) |
| 67 |
} |
| 68 |
defer file.Close() |
| 69 |
|
| 70 |
cs, err := minio.ChecksumCRC32C.ChecksumReader(file) |
| 71 |
if err != nil { |
| 72 |
log.Fatalln(err) |
| 73 |
} |
| 74 |
|
| 75 |
// Seek to beginning before upload. |
| 76 |
file.Seek(0, io.SeekStart) |
| 77 |
|
| 78 |
fanOutReq := minio.PutObjectFanOutRequest{ |
| 79 |
Entries: []minio.PutObjectFanOutEntry{ |
| 80 |
{Key: "my1-prefix/1.txt"}, |
| 81 |
{Key: "my1-prefix/2.txt"}, |
| 82 |
{Key: "my1-prefix/3.txt"}, |
| 83 |
{Key: "my1-prefix/4.txt"}, |
| 84 |
{Key: "my1-prefix/5.txt"}, |
| 85 |
{Key: "my1-prefix/6.txt"}, |
| 86 |
}, |
| 87 |
SSE: encrypt.NewSSE(), |
| 88 |
Checksum: cs, |
| 89 |
} |
| 90 |
|
| 91 |
fanOutResp, err := minioClient.PutObjectFanOut(context.Background(), YOURBUCKET, file, fanOutReq) |
| 92 |
if err != nil { |
| 93 |
log.Fatalln(err) |
| 94 |
} |
| 95 |
|
| 96 |
for _, resp := range fanOutResp { |
| 97 |
fmt.Println(resp) |
| 98 |
} |
| 99 |
} |