composeobject.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // +build ignore
  2. /*
  3. * Minio Go Library for Amazon S3 Compatible Cloud Storage
  4. * Copyright 2015-2017 Minio, Inc.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package main
  19. import (
  20. "log"
  21. minio "github.com/minio/minio-go"
  22. )
  23. func main() {
  24. // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-testfile, my-bucketname and
  25. // my-objectname are dummy values, please replace them with original values.
  26. // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access.
  27. // This boolean value is the last argument for New().
  28. // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically
  29. // determined based on the Endpoint value.
  30. s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true)
  31. if err != nil {
  32. log.Fatalln(err)
  33. }
  34. // Enable trace.
  35. // s3Client.TraceOn(os.Stderr)
  36. // Prepare source decryption key (here we assume same key to
  37. // decrypt all source objects.)
  38. decKey := minio.NewSSEInfo([]byte{1, 2, 3}, "")
  39. // Source objects to concatenate. We also specify decryption
  40. // key for each
  41. src1 := minio.NewSourceInfo("bucket1", "object1", &decKey)
  42. src1.SetMatchETagCond("31624deb84149d2f8ef9c385918b653a")
  43. src2 := minio.NewSourceInfo("bucket2", "object2", &decKey)
  44. src2.SetMatchETagCond("f8ef9c385918b653a31624deb84149d2")
  45. src3 := minio.NewSourceInfo("bucket3", "object3", &decKey)
  46. src3.SetMatchETagCond("5918b653a31624deb84149d2f8ef9c38")
  47. // Create slice of sources.
  48. srcs := []minio.SourceInfo{src1, src2, src3}
  49. // Prepare destination encryption key
  50. encKey := minio.NewSSEInfo([]byte{8, 9, 0}, "")
  51. // Create destination info
  52. dst, err := minio.NewDestinationInfo("bucket", "object", &encKey, nil)
  53. if err != nil {
  54. log.Fatalln(err)
  55. }
  56. err = s3Client.ComposeObject(dst, srcs)
  57. if err != nil {
  58. log.Fatalln(err)
  59. }
  60. log.Println("Composed object successfully.")
  61. }