-
-
Save linyiru/2ba928f0a2acd6848027fb4e7b17890f to your computer and use it in GitHub Desktop.
Example on how to create a signed URL on Google Cloud Storage with Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
"google.golang.org/cloud/storage" | |
) | |
const ( | |
projectID = "myProject-1234" | |
) | |
func main() { | |
bucket := "mybucket" | |
filename := "myFilename" | |
method := "PUT" | |
expires := time.Now().Add(time.Second * 60) | |
url, err := storage.SignedURL(bucket, filename, &storage.SignedURLOptions{ | |
GoogleAccessID: "[email protected]", | |
PrivateKey: []byte("-----BEGIN PRIVATE KEY-----\nXXXXXXXX"), | |
Method: method, | |
Expires: expires, | |
}) | |
if err != nil { | |
fmt.Println("Error " + err.Error()) | |
} | |
fmt.Println("URL = " + url) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from: https://medium.com/@fluxcapacitor/using-golang-to-create-google-cloud-signed-urls-to-upload-images-using-reactjs-846cfd7ba602