Question
Presign link for download not working with aws sdk golang
Hello guys, I have some issues to make work a DO spaces presign url in aws golang sdk.
I have the following code snippet:
import (
"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"
"github.com/labstack/echo"
"log"
"net/http"
"parameters"
"time"
)
key := parameters.ObjectStorageKey
secret := parameters.ObjectStorageSecret
s3Config := &aws.Config{
Credentials: credentials.NewStaticCredentials(key, secret, ""),
Endpoint: aws.String(parameters.ObjectStorageEndpoint),
Region: aws.String(parameters.ObjectStorageRegion),
}
newSession, err := session.NewSession(s3Config)
if err != nil {
return "", err
}
s3Client := s3.New(newSession)
req, _ := s3Client.GetObjectRequest(&s3.GetObjectInput{
Bucket: aws.String(parameters.ObjectStorageBucketErp),
Key: aws.String("MY_OBJECT_KEY"),
})
urlStr, header, err := req.PresignRequest(10 * time.Minute)
if err != nil {
log.Print(err)
}
log.Print(urlstr)
It is generating the url, but when I put it to browser it gives me access denied error. When I generate a link in the control panel it is working without any issue.
What I experienced there is a difference in the link generated by my code and in the control panel.
Link generated in the control panel look like this:
https://fra1.digitaloceanspaces.com/**MY_BUCKET**/MY_OBJECT_KEY
Link generated by my code is like this:
https://MY_BUCKET.fra1.digitaloceanspaces.com/MYOBJECTKEY
I don’t know if its cause the problem or not, but I stuck here…
Is there anything what I’m doing wrong?
Thanks!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×