Created
February 14, 2024 08:00
go-presigned-post example usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/TrueSparrowSystems/go-presigned-post" | |
) | |
func main() { | |
// Set AWS credentials and configuration | |
awsCredentials := presignedpost.AwsCredentialsAndConfig{ | |
Region: "your-aws-region", | |
Bucket: "your-s3-bucket", | |
AccessKeyID: "your-access-key-id", | |
SecretAccessKey: "your-secret-access-key", | |
} | |
// Set the key for the S3 object | |
key := "path/to/upload/file.txt" | |
// Set optional policy options | |
policyOptions := presignedpost.PolicyOptions{ | |
ExpiryInSeconds: nil, // Default is 1 hour | |
ContentType: "", // Content type of the S3 object | |
MaxFileSizeInBytes: 0, // Maximum allowed file size in the policy | |
Acl: "", // AWS S3 ACL (Access Control List) | |
CacheControl: "", // Cache control header | |
} | |
// Generate presigned POST URL and fields | |
postUrl, postFields, err := presignedpost.PresignedPostObject(key, awsCredentials, policyOptions) | |
if err != nil { | |
fmt.Println("Error:", err) | |
return | |
} | |
// Use postUrl and postFields to upload a file using HTTP POST | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment