MCPcopy
hub / github.com/minio/minio-go / main

Function main

examples/s3/copyobject.go:32–80  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30)
31
32func main() {
33 // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-testfile, my-bucketname and
34 // my-objectname are dummy values, please replace them with original values.
35
36 // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access.
37 // This boolean value is the last argument for New().
38
39 // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically
40 // determined based on the Endpoint value.
41 s3Client, err := minio.New("s3.amazonaws.com", &minio.Options{
42 Creds: credentials.NewStaticV4("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", ""),
43 Secure: true,
44 })
45 if err != nil {
46 log.Fatalln(err)
47 }
48
49 // Enable trace.
50 // s3Client.TraceOn(os.Stderr)
51
52 // Source object
53 src := minio.CopySrcOptions{
54 Bucket: "my-sourcebucketname",
55 Object: "my-sourceobjectname",
56 // All following conditions are allowed and can be combined together.
57 // Set modified condition, copy object modified since 2014 April.
58 MatchModifiedSince: time.Date(2014, time.April, 0, 0, 0, 0, 0, time.UTC),
59 // Set unmodified condition, copy object unmodified since 2014 April.
60 // MatchUnmodifiedSince: time.Date(2014, time.April, 0, 0, 0, 0, 0, time.UTC),
61 // Set matching ETag condition, copy object which matches the following ETag.
62 // MatchETag: "31624deb84149d2f8ef9c385918b653a",
63 // Set matching ETag copy object which does not match the following ETag.
64 // NoMatchETag: "31624deb84149d2f8ef9c385918b653a",
65 }
66
67 // Destination object
68 dst := minio.CopyDestOptions{
69 Bucket: "my-bucketname",
70 Object: "my-objectname",
71 }
72
73 // Initiate copy object.
74 ui, err := s3Client.CopyObject(context.Background(), dst, src)
75 if err != nil {
76 log.Fatalln(err)
77 }
78
79 log.Printf("Copied %s, successfully to %s - UploadInfo %v\n", dst, src, ui)
80}

Callers

nothing calls this directly

Calls 2

NewStaticV4Function · 0.92
CopyObjectMethod · 0.45

Tested by

no test coverage detected