2014-03-25 102 views
2

我想在我的應用程序引擎項目上使用谷歌遠程API來上傳本地文件到我的應用程序的默認雲存儲桶。谷歌雲存儲客戶端與本地客戶端上的遠程API

我配置了我的app.yaml以啓用遠程API。我能夠訪問我的存儲桶並從中上傳/訪問文件。我跑我的Python的控制檯,並嘗試寫入桶用下面的代碼:

from google.appengine.ext.remote_api import remote_api_stub 
from google.appengine.api import app_identity 
import cloudstorage 

def auth_func(): 
    return ('[email protected]', '*******') 

remote_api_stub.ConfigureRemoteApi('my-app-id', '/_ah/remote_api', auth_func,'my-app-id.appspot.com') 
filename = "/"+app_identity.get_default_gcs_bucket_name()+ "/myfile.txt" 
gcs_file = cloudstorage.open(filename,'w',content_type='text/plain',options={'x-goog-meta-foo': 'foo','x-goog-meta-bar': 'bar'}) 

我看到下面的回覆:

WARNING:root:suspended generator urlfetch(context.py:1214) raised DownloadError(Unable to fetch URL: http://None/_ah/gcs/my-app-id.appspot.com/myfile.txt) 

通知的

http://None/_ah/gcs..... 

我不t認爲應該是網址的一部分。 GoogleAppEngineCloudStorageClient v1.9.0.0有問題嗎?我也在使用Google App Engine 1.9.1。

任何想法?

+0

'app_identity.get_default_gcs_bucket_name檢查您的環境()'是沒有得到設置看起來是這樣的。你能確認嗎? – Drewness

+0

是的,它返回my-app-id.appspot.com – bvk

+0

嘗試更改'filename =「/%s/myfile.txt」%app_identity.get_default_gcs_bucket_name()' – Drewness

回答

0

如果我理解正確,您想要將本地文本文件上傳到特定的存儲桶。我不認爲你正在做的事情會起作用。

另一種方法是放棄RemoteAPI並使用Cloud Storage API將其上載。

1

谷歌雲存儲客戶端不尊重remote_api_stub,並認爲你是在本地運行腳本

os.environ['SERVER_SOFTWARE'] = 'Development (remote_api)/1.0' 

甚至

os.environ['SERVER_SOFTWARE'] = '' 

會有所幫助。

功能,從common.py

def local_run(): 
    """Whether we should hit GCS dev appserver stub.""" 
    server_software = os.environ.get('SERVER_SOFTWARE') 
    if server_software is None: 
    return True 
    if 'remote_api' in server_software: 
    return False 
    if server_software.startswith(('Development', 'testutil')): 
    return True 
    return False