<p>I'm wondering if anyone has experience with cloud storage? I have followed the instructions here: <a href="https://cloud.google.com/storage/docs/json_api/v1/json-api-go-samples" rel="nofollow">https://cloud.google.com/storage/docs/json_api/v1/json-api-go-samples</a></p>
<p>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</p>
<p>When I return the error to the browser, I get the following:</p>
<pre><code>googleapi: Error 401: Invalid Credentials, authError
</code></pre>
<p>This is what I see in the terminal:</p>
<pre><code>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
</code></pre>
<p>Any help is greatly appreciated!</p>
<p><strong>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</strong></p>
<hr/>**评论:**<br/><br/>miko5054: <pre><p>this is how i work with GCS
First i'm creating a Storage Context
func GetStorageContext(c context.Context) context.Context {</p>
<pre><code> 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
}
</code></pre>
<p>Then im using the Context in order to do stuff </p>
<pre><code> storageCtx := GetStorageContext(ctx)
err = storage.DeleteObject(storageCtx, bucket, storageId)
</code></pre>
<p>Make sure that you are using the correct Context
<strong>ctx := appengine.NewContext(r)</strong> </p></pre>dahlma: <pre><p>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?</p></pre>dahlma: <pre><p>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</p></pre>loganjspears: <pre><p>I would try gsutil if you can get away with it. It's a great tool.</p></pre>dwevlo: <pre><p>Here's an example for appengine: <a href="https://github.com/calebdoxsey/tutorials/blob/master/appengine/cms/api.go#L234" rel="nofollow">https://github.com/calebdoxsey/tutorials/blob/master/appengine/cms/api.go#L234</a></p>
<p>The imports are a real mess right now. Here's what I had:</p>
<pre><code> "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"
</code></pre>
<p>I had the same problem locally: <a href="https://code.google.com/p/googleappengine/issues/detail?id=11690" rel="nofollow">https://code.google.com/p/googleappengine/issues/detail?id=11690</a>. Downgrading/Upgrading your appengine server may help.</p>
<p>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.</p>
<p>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.</p></pre>dahlma: <pre><p>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.</p></pre>bradfitz: <pre><p>Use the higher-level <a href="https://godoc.org/google.golang.org/cloud/storage" rel="nofollow">https://godoc.org/google.golang.org/cloud/storage</a> instead.</p></pre>dahlma: <pre><p>I was originally but then saw on the docs it's unstable, you think it's fit for production?</p></pre>bradfitz: <pre><p>We use it in production. It should be stable. I'll fix the docs.</p></pre>dahlma: <pre><p>Awesome! Thank you, I'll take a look at it </p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传