Google Cloud Storage

agolangf · 2015-04-25 08:08:42 · 3292 次点击    
这是一个分享于 2015-04-25 08:08:42 的资源,其中的信息可能已经有所发展或是发生改变。

I'm wondering if anyone has experience with cloud storage? I have followed the instructions here: https://cloud.google.com/storage/docs/json_api/v1/json-api-go-samples

I actually have it working fine when I push code to app engine, my initial problem was that I was using a bucket in a different project but I fixed that with ACL's, but I can't test anything on development

When I return the error to the browser, I get the following:

googleapi: Error 401: Invalid Credentials, authError

This is what I see in the terminal:

2015/04/25 08:07:19 bucket app_default_bucket
ERROR    2015-04-25 08:07:19,162 api_server.py:221] Exception while handling service_name: "app_identity_service"
method: "GetAccessToken"
request: "\n7https://www.googleapis.com/auth/devstorage.full_control"
request_id: "rPzulWmQCc"

Traceback (most recent call last):
  File "/Users/dougbarrett/go_appengine/google/appengine/tools/devappserver2/api_server.py", line 196, in _handle_POST
    api_response = _execute_request(request).Encode()
  File "/Users/dougbarrett/go_appengine/google/appengine/tools/devappserver2/api_server.py", line 154, in _execute_request
    make_request()
  File "/Users/dougbarrett/go_appengine/google/appengine/tools/devappserver2/api_server.py", line 149, in make_request
    request_id)
  File "/Users/dougbarrett/go_appengine/google/appengine/api/apiproxy_stub.py", line 131, in MakeSyncCall
    method(request, response)
  File "/Users/dougbarrett/go_appengine/google/appengine/api/app_identity/app_identity_defaultcredentialsbased_stub.py", line 180, in _Dynamic_GetAccessToken
    response.set_access_token(token['access_token'])
TypeError: tuple indices must be integers, not str

ERROR    2015-04-25 08:07:20,680 api_server.py:221] Exception while handling service_name: "app_identity_service"
method: "GetAccessToken"
request: "\n7https://www.googleapis.com/auth/devstorage.full_control"
request_id: "rPzulWmQCc"

Traceback (most recent call last):
  File "/Users/dougbarrett/go_appengine/google/appengine/tools/devappserver2/api_server.py", line 196, in _handle_POST
    api_response = _execute_request(request).Encode()
  File "/Users/dougbarrett/go_appengine/google/appengine/tools/devappserver2/api_server.py", line 154, in _execute_request
    make_request()
  File "/Users/dougbarrett/go_appengine/google/appengine/tools/devappserver2/api_server.py", line 149, in make_request
    request_id)
  File "/Users/dougbarrett/go_appengine/google/appengine/api/apiproxy_stub.py", line 131, in MakeSyncCall
    method(request, response)
  File "/Users/dougbarrett/go_appengine/google/appengine/api/app_identity/app_identity_defaultcredentialsbased_stub.py", line 180, in _Dynamic_GetAccessToken
    response.set_access_token(token['access_token'])
TypeError: tuple indices must be integers, not str

INFO     2015-04-25 08:07:21,950 module.py:737] default: "POST /businessowners/save HTTP/1.1" 500 53

Any help is greatly appreciated!

EDIT: This was solved I was using golang app engine 1.9.18 which had this bug, updating to 1.9.19 worked...just wanted to note incase anyone else runs into this issue too


评论:

miko5054:

this is how i work with GCS First i'm creating a Storage Context func GetStorageContext(c context.Context) context.Context {

     hc := &http.Client{
    Transport: &oauth2.Transport{
        Source: google.AppEngineTokenSource(c, storage.ScopeFullControl),
        Base:   &urlfetch.Transport{Context: c},
    },
}
storageCtx := cloud.WithContext(c, AppengineAppID, hc)
return storageCtx
 }

Then im using the Context in order to do stuff

         storageCtx := GetStorageContext(ctx)
           err = storage.DeleteObject(storageCtx, bucket, storageId)

Make sure that you are using the correct Context ctx := appengine.NewContext(r)

dahlma:

I must be missing something because I swear I've tried the code like that. It works fine on dev? I heard when you're running it locally you see the objects in blob storage?

dahlma:

Also what are you importing? I'm hearing that some import paths are being depreciated. If you look at the article I posted, it's from a few days ago and is a completely different setup and method of uploading files. That's from the cloud files API docs, the example you posted looks more reminiscent of the app engine examples

loganjspears:

I would try gsutil if you can get away with it. It's a great tool.

dwevlo:

Here's an example for appengine: https://github.com/calebdoxsey/tutorials/blob/master/appengine/cms/api.go#L234

The imports are a real mess right now. Here's what I had:

    "golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"google.golang.org/appengine"
"google.golang.org/appengine/datastore"
"google.golang.org/appengine/file"
"google.golang.org/appengine/urlfetch"
"google.golang.org/cloud"
"google.golang.org/cloud/storage"

I had the same problem locally: https://code.google.com/p/googleappengine/issues/detail?id=11690. Downgrading/Upgrading your appengine server may help.

I've been pretty disappointed with appengine. It feels like there's no one running the show at google, they're in the middle of rewriting everything, and no one bothers to make sure it still works for developers. Half the documentation is obsolete.

You might have better luck using a real bucket with real access keys. The GCS library by itself is probably more reliable/predictable than the GCS<->appengine integration.

dahlma:

thanks! i was using the GCS library, it was due to a bug in goapp 1.9.18 like your link suggested, i updated to 1.9.19 and everything worked perfectly. Pissed I wasted 5 hours when I knew there was an update available, but glad I know I'm not crazy.

bradfitz:

Use the higher-level https://godoc.org/google.golang.org/cloud/storage instead.

dahlma:

I was originally but then saw on the docs it's unstable, you think it's fit for production?

bradfitz:

We use it in production. It should be stable. I'll fix the docs.

dahlma:

Awesome! Thank you, I'll take a look at it


入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

3292 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传