putobject-s3-accelerate.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. "os"
  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 S3 transfer accelerate endpoint.
  36. s3Client.SetS3TransferAccelerate("s3-accelerate.amazonaws.com")
  37. object, err := os.Open("my-testfile")
  38. if err != nil {
  39. log.Fatalln(err)
  40. }
  41. defer object.Close()
  42. objectStat, err := object.Stat()
  43. if err != nil {
  44. log.Fatalln(err)
  45. }
  46. n, err := s3Client.PutObject("my-bucketname", "my-objectname", object, objectStat.Size(), minio.PutObjectOptions{ContentType: "application/octet-stream"})
  47. if err != nil {
  48. log.Fatalln(err)
  49. }
  50. log.Println("Uploaded", "my-objectname", " of size: ", n, "Successfully.")
  51. }