presignedpostpolicy.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. "fmt"
  21. "log"
  22. "time"
  23. "github.com/minio/minio-go"
  24. )
  25. func main() {
  26. // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-objectname
  27. // are dummy values, please replace them with original values.
  28. // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access.
  29. // This boolean value is the last argument for New().
  30. // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically
  31. // determined based on the Endpoint value.
  32. s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true)
  33. if err != nil {
  34. log.Fatalln(err)
  35. }
  36. policy := minio.NewPostPolicy()
  37. policy.SetBucket("my-bucketname")
  38. policy.SetKey("my-objectname")
  39. // Expires in 10 days.
  40. policy.SetExpires(time.Now().UTC().AddDate(0, 0, 10))
  41. // Returns form data for POST form request.
  42. url, formData, err := s3Client.PresignedPostPolicy(policy)
  43. if err != nil {
  44. log.Fatalln(err)
  45. }
  46. fmt.Printf("curl ")
  47. for k, v := range formData {
  48. fmt.Printf("-F %s=%s ", k, v)
  49. }
  50. fmt.Printf("-F file=@/etc/bash.bashrc ")
  51. fmt.Printf("%s\n", url)
  52. }