By Zsolt Bodnár
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/MY_OBJECT_KEY
I don’t know if its cause the problem or not, but I stuck here… Is there anything what I’m doing wrong?
Thanks!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Accepted Answer
Next day it is just working… Don’t know what was the problem yesterday, but now it’s fine. So above you can see a working golang example :).
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.