I wrote the code to issue PreSignedUrl in Golang, so I will leave it.
package main
import (
"context"
"fmt"
"time"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
//S3 connection information
accessKey := os.Getenv("AWS_ACCSESS_KEY")
secretKey := os.Getenv("AWS_SECRET_KEY")
region := aws.String(os.Getenv("CUEE_DB_REGION"))
creds := credentials.NewStaticCredentials(accsessKey, secretKey, "")
session := session.Must(session.NewSession(&aws.Config{
Credentials: creds,
Region: region,
}))
svc := s3.New(session)
c, _ := svc.PutObjectRequest(&s3.PutObjectInput{
Bucket: aws.String("Bucket name"),
Key: aws.String("/diectory/filename"),
})
url, err := c.Presign(15 * time.Minute)
if err != nil {
fmt.Println("error presigning request", err)
return nil, err
}
fmt.Println(url)
}
You can set the expiration date here
url, err := c.Presign(15 * time.Minute)
official https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/s3-example-presigned-urls.html
You can upload by including the file in Body and accessing the issued URL
Recommended Posts