copyobject.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. "time"
  22. "github.com/minio/minio-go"
  23. )
  24. func main() {
  25. // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-testfile, my-bucketname and
  26. // my-objectname are dummy values, please replace them with original values.
  27. // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access.
  28. // This boolean value is the last argument for New().
  29. // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically
  30. // determined based on the Endpoint value.
  31. s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true)
  32. if err != nil {
  33. log.Fatalln(err)
  34. }
  35. // Enable trace.
  36. // s3Client.TraceOn(os.Stderr)
  37. // Source object
  38. src := minio.NewSourceInfo("my-sourcebucketname", "my-sourceobjectname", nil)
  39. // All following conditions are allowed and can be combined together.
  40. // Set modified condition, copy object modified since 2014 April.
  41. src.SetModifiedSinceCond(time.Date(2014, time.April, 0, 0, 0, 0, 0, time.UTC))
  42. // Set unmodified condition, copy object unmodified since 2014 April.
  43. // src.SetUnmodifiedSinceCond(time.Date(2014, time.April, 0, 0, 0, 0, 0, time.UTC))
  44. // Set matching ETag condition, copy object which matches the following ETag.
  45. // src.SetMatchETagCond("31624deb84149d2f8ef9c385918b653a")
  46. // Set matching ETag except condition, copy object which does not match the following ETag.
  47. // src.SetMatchETagExceptCond("31624deb84149d2f8ef9c385918b653a")
  48. // Destination object
  49. dst, err := minio.NewDestinationInfo("my-bucketname", "my-objectname", nil, nil)
  50. if err != nil {
  51. log.Fatalln(err)
  52. }
  53. // Initiate copy object.
  54. err = s3Client.CopyObject(dst, src)
  55. if err != nil {
  56. log.Fatalln(err)
  57. }
  58. log.Println("Copied source object /my-sourcebucketname/my-sourceobjectname to destination /my-bucketname/my-objectname Successfully.")
  59. }