Google Cloud Storage

agolangf · · 3174 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;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&#39;s, but I can&#39;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: &#34;app_identity_service&#34; method: &#34;GetAccessToken&#34; request: &#34;\n7https://www.googleapis.com/auth/devstorage.full_control&#34; request_id: &#34;rPzulWmQCc&#34; Traceback (most recent call last): File &#34;/Users/dougbarrett/go_appengine/google/appengine/tools/devappserver2/api_server.py&#34;, line 196, in _handle_POST api_response = _execute_request(request).Encode() File &#34;/Users/dougbarrett/go_appengine/google/appengine/tools/devappserver2/api_server.py&#34;, line 154, in _execute_request make_request() File &#34;/Users/dougbarrett/go_appengine/google/appengine/tools/devappserver2/api_server.py&#34;, line 149, in make_request request_id) File &#34;/Users/dougbarrett/go_appengine/google/appengine/api/apiproxy_stub.py&#34;, line 131, in MakeSyncCall method(request, response) File &#34;/Users/dougbarrett/go_appengine/google/appengine/api/app_identity/app_identity_defaultcredentialsbased_stub.py&#34;, line 180, in _Dynamic_GetAccessToken response.set_access_token(token[&#39;access_token&#39;]) 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: &#34;app_identity_service&#34; method: &#34;GetAccessToken&#34; request: &#34;\n7https://www.googleapis.com/auth/devstorage.full_control&#34; request_id: &#34;rPzulWmQCc&#34; Traceback (most recent call last): File &#34;/Users/dougbarrett/go_appengine/google/appengine/tools/devappserver2/api_server.py&#34;, line 196, in _handle_POST api_response = _execute_request(request).Encode() File &#34;/Users/dougbarrett/go_appengine/google/appengine/tools/devappserver2/api_server.py&#34;, line 154, in _execute_request make_request() File &#34;/Users/dougbarrett/go_appengine/google/appengine/tools/devappserver2/api_server.py&#34;, line 149, in make_request request_id) File &#34;/Users/dougbarrett/go_appengine/google/appengine/api/apiproxy_stub.py&#34;, line 131, in MakeSyncCall method(request, response) File &#34;/Users/dougbarrett/go_appengine/google/appengine/api/app_identity/app_identity_defaultcredentialsbased_stub.py&#34;, line 180, in _Dynamic_GetAccessToken response.set_access_token(token[&#39;access_token&#39;]) TypeError: tuple indices must be integers, not str INFO 2015-04-25 08:07:21,950 module.py:737] default: &#34;POST /businessowners/save HTTP/1.1&#34; 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&#39;m creating a Storage Context func GetStorageContext(c context.Context) context.Context {</p> <pre><code> hc := &amp;http.Client{ Transport: &amp;oauth2.Transport{ Source: google.AppEngineTokenSource(c, storage.ScopeFullControl), Base: &amp;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&#39;ve tried the code like that. It works fine on dev? I heard when you&#39;re running it locally you see the objects in blob storage?</p></pre>dahlma: <pre><p>Also what are you importing? I&#39;m hearing that some import paths are being depreciated. If you look at the article I posted, it&#39;s from a few days ago and is a completely different setup and method of uploading files. That&#39;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&#39;s a great tool.</p></pre>dwevlo: <pre><p>Here&#39;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&#39;s what I had:</p> <pre><code> &#34;golang.org/x/oauth2&#34; &#34;golang.org/x/oauth2/google&#34; &#34;google.golang.org/appengine&#34; &#34;google.golang.org/appengine/datastore&#34; &#34;google.golang.org/appengine/file&#34; &#34;google.golang.org/appengine/urlfetch&#34; &#34;google.golang.org/cloud&#34; &#34;google.golang.org/cloud/storage&#34; </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&#39;ve been pretty disappointed with appengine. It feels like there&#39;s no one running the show at google, they&#39;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&lt;-&gt;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&#39;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&#39;s unstable, you think it&#39;s fit for production?</p></pre>bradfitz: <pre><p>We use it in production. It should be stable. I&#39;ll fix the docs.</p></pre>dahlma: <pre><p>Awesome! Thank you, I&#39;ll take a look at it </p></pre>

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

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