how to get unsigned url (not signed url)

146 views
Skip to first unread message

Alexander Mills

unread,
Dec 21, 2020, 5:55:18 PM12/21/20
to golang-nuts
this is a little irritating lol, i can get a signed url via:

bucket := "bnk-photos"
filename := "mypic3.json"
method := "PUT"
expires := time.Now().Add(time.Minute * 10)

url, err := storage.SignedURL(bucket, filename, &storage.SignedURLOptions{
GoogleAccessID: cfg.Email,
PrivateKey: cfg.PrivateKey,
Method: method,
Expires: expires,
ContentType: "binary/octet-stream",
})


but I just want an unsigned url?
how?

Kurtis Rader

unread,
Dec 21, 2020, 5:59:20 PM12/21/20
to Alexander Mills, golang-nuts
What is the "storage" package? It's not part of the Go stdlib. Also, what is a "signed" URL. I've never heard that phrase before your email.
 
--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

Uli Kunitz

unread,
Dec 21, 2020, 6:53:37 PM12/21/20
to golang-nuts
It is the Google Cloud Storage package. Documentation is here: https://pkg.go.dev/cloud.google.com/go/storage

Signed URLs are URLs that allow access to an object in the cloud storage without any other authentication mechanism: https://cloud.google.com/storage/docs/access-control/signed-urls

Google cloud storage organizes data into buckets and objects. A single site should be represented by one bucket and the files as the objects in the site. The explanation how to setup a static website with Google Cloud Storage can be found here: https://cloud.google.com/storage/docs/hosting-static-website

The URL for an object is then https://example.com/<object-name>

Alexander Mills

unread,
Dec 21, 2020, 6:59:31 PM12/21/20
to golang-nuts
that is not a google url:

 https://example.com/<object-name>

?

Amnon

unread,
Dec 22, 2020, 1:52:34 AM12/22/20
to golang-nuts
I too was puzzled by the term signed and unsigned URL.
But I have come across signed and unsigned integers.
An unsigned integer (such as uint64) can only take positive values and zero, whereas a signed integer can also hold negative values.
So presumably an unsigned URL can only point to positive web sites, whereas a signed URL can also point to
negative web sites such as malware, fake news, conspiracy theories etc.

Merry Xmas and happy new year to all the gophers here!
Wising everyone a much better 2021.
- amnon

Uli Kunitz

unread,
Dec 22, 2020, 4:07:37 AM12/22/20
to golang-nuts
This assumes that you have made site publicly available as described in the document I have linked.

David Finkel

unread,
Dec 24, 2020, 5:32:14 PM12/24/20
to Alexander Mills, golang-nuts
 
If it's an object that already exists that you want to provide access to the current version, you want: ObjectAttrs.MediaLink, so you'd do something like:

gcsClient, clientErr := storage.NewClient(ctx)
// if clientErr != nil {....
obj := gcsClient.Bucket(bucket).Object(filename)
objattr, attrErr := obj.Attrs(ctx)
// if attrErr != nil { ...
fmt.Println(objattr.MediaLink) // this

On the other hand, your example uses the PUT method for signing the URL, in which case I think you'd need to construct the URL directly as either
fmt.Sprintf("%s.storage.googleapis.com/%s", bucket, filename)

fmt.Sprintf("https://storage.googleapis.com/storage/v1/b/%s/o/%s", bucket, filename) 

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/f00bd659-dbed-4161-8b6c-456f41ccbb22n%40googlegroups.com.

Alexander Mills

unread,
Dec 24, 2020, 6:00:29 PM12/24/20
to David Finkel, golang-nuts
> If it's an object that already exists

no, sadly it's not, i need to generate the url to which i can upload the image to, that url should be unsigned not signed.
that being said, a signed url might be fine.
--
Alexander D. Mills
New cell phone # (415)730-1805
linkedin.com/in/alexanderdmills
Reply all
Reply to author
Forward
0 new messages