2016-06-09 30 views
0

我使用GCSService在GoogleCloudStorage存储桶中写入文件,所有这些都可以在线实例正常工作,但是当我想在本地开发服务器上测试我的代码时,不可能写入一个存储桶(像数据存储一样模拟本地存储区)。 额外的困难我试图写在我的本地服务器与胖客户端的远程API,我在网上搜索我没有找到我的答案。 当我打电话给我的createOrUpdate()方法,我有这样的例外:Google App引擎Java API在本地开发服务器上写入存储桶不起作用

com.google.appengine.tools.cloudstorage.NonRetriableException: java.lang.RuntimeException: Server replied with 403, verify ACLs are set correctly on the object and bucket: Request: POST https://storage.googleapis.com/InstanceName/FileInfos 

它似乎试图在我的网上桶写...

GcsService gcsService = GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance()); 
... 
RemoteApiOptions destination = RemoteConnection.connect(destinationServer); 
RemoteApiInstaller destinationInstaller = new RemoteApiInstaller(); 
destinationInstaller.install(destination); 
try 
{ 
    GcsOutputChannel outputChannel = gcsService.createOrReplace(new GcsFilename(destinationBucketServer, fileInfo.getFilename()), 
      GcsFileOptions.getDefaultInstance()); 

    outputChannel.write(ByteBuffer.wrap(data)); 
    outputChannel.close(); 
} 
catch (Exception e) 
{ 
    .... 
} 
finally 
{ 
    buffer.flush(); 
    destinationInstaller.uninstall(); 
} 

用同样的代码,我可以在数据存储中没有写任何问题,这只是一个存储问题。

回答

1

查看Google Cloud Storage Errors and Error HandlingService Account文档。

403表示用户未被授权发出请求。在你的GCE实例上运行时,我猜你的代码是在一个服务帐户中运行的,该服务帐户对你的存储桶有写入权限。在本地运行时,您必须提供相应的凭据才能执行相同的操作。

+0

是的我知道403是什么意思,但是我可以在本地存储桶中配置本地ACL,但是我没有发现任何有关此配置的信息。在例外情况下,有远程URL POST https://storage.googleapis.com/InstanceName/FileInfos喜欢它尝试在线上传。 感谢您的回答 – Benjyyyyy

+0

除此之外,我使用开发服务器凭证连接到本地服务器,我在这里错过了什么?为什么此代码不提供访问权限? new RemoteApiOptions()。server(server.getAddress(),server.getPort())。useDevelopmentServerCredential(); – Benjyyyyy

0

我想出了为什么这不起作用,实际上是通过RemoteAPI调用GCS不写在本地服务器上,它写在网上的bucket上。 这就是为什么我没有正确的ACL,我的代码尝试连接到云存储。 但是现在我不知道如何强制GCSService在本地服务器上写入。

+0

App Engine支持数据存储模拟。你确定它支持云存储模拟吗? – jarmod

+0

是的,它在本地环境中使用GCSService时支持云存储模拟。就我而言,我们尝试通过RemoteAPI写入本地云存储,在这种情况下,它不起作用 – Benjyyyyy

相关问题