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/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!


Submit an answer


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!

Sign In or Sign Up to Answer

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.

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 :).

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel