I got this code to get a signedURL:
import (
"net/http"
"time"
"cloud.google.com/go/storage"
"google.golang.org/appengine"
)
//Don´t worry about the errors, I´m handling them
func CreatSignedURL(r *http.Request) (string, error) {
ctx := appengine.NewContext(r)
acc, _ := appengine.ServiceAccount(ctx)
filename := "fileName"
bucket := "bucketName"
expires := time.Now().Add(time.Hour * 2)
url, _ := storage.SignedURL(bucket, filename, &storage.SignedURLOptions{
GoogleAccessID: acc,
SignBytes: func(b []byte) ([]byte, error) {
_, signedBytes, err2 := appengine.SignBytes(ctx, b)
return signedBytes, err2
},
Method: "PUT",
Expires: expires,
})
return url, nil
}
But, I want to authenticate similar as the code above with resumable upload
import (
"fmt"
"net/http"
)
func ResumeUploadURL(nameBucket, nombreObjeto string) string {
url := "https://www.googleapis.com/upload/storage/v1/b/" + nameBucket + "/o?uploadType=resumable&name=" + nombreObjeto
client := &http.Client{}
r, _ := http.NewRequest("POST", url, nil) // URL-encoded payload
r.Header.Add("Authorization", "auth_token=??????????") // What should I use instead?
r.Header.Add("Content-Length", "0")
resp, _ := client.Do(r)
.....
}
But I need auth_token,where auth_token I need to get it like it´s described here https://cloud.google.com/storage/docs/json_api/v1/how-tos/authorizing But I would wanna avoid that becasue it seems pretty silly to me to authenticate in that way if I can easy authenticate with signedURL and with resume upload can´t