如何验证appEngine flexible的可恢复上传,类似于golang中的SignedURL
我用这个密码来得到一个签名URL:如何验证appEngine flexible的可恢复上传,类似于golang中的SignedURL,go,google-cloud-storage,app-engine-flexible,Go,Google Cloud Storage,App Engine Flexible,我用这个密码来得到一个签名URL: 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.
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
}
但是,我想通过类似于上面代码的可恢复上传进行身份验证
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)
.....
}
但是我需要auth_token,其中auth_token我需要像这里描述的那样获得它,但我想避免这样做,因为如果我可以轻松地通过signedURL和resume upload进行身份验证,那么以这种方式进行身份验证对我来说是相当愚蠢的,因为没有好的文档,我想避免使用auth2,在阅读了大量文档并尝试了许多失败的例子之后,我终于开始工作了,以下是使用json api使令牌承载器成为恢复上传的步骤 从console.cloud.google.com/api/credentials下载JSON凭据 1.1选择创建凭据 1.2选择服务帐户密钥 1.3选择您的帐户 1.4选择JSON->创建 1.4它将下载包含您所需信息的JSON 创建oauth2/jwt令牌源 进口 上下文 net/http golang.org/x/oauth2/jwt var config=&jwt.config{ 电邮:someEmail@something.com, PrivateKey:[]字节---开始私钥---\n开始私钥\n结束私钥---\n, PrivateKeyID:非常私人的东西, 作用域:[]字符串{},//如果需要,可以更改/添加作用域 令牌URL:, } 令牌,err:=config.TokenSourcecontext.Background.token//handle error 3现在您有了要使用的id,它位于方法token.AccessToken中 所有获取url的过程,我都放在这里: