我使用GCSService在GoogleCloudStorage存储桶中写入文件,所有这些在联机实例中都工作得很好,但是当我想在本地开发服务器上测试我的代码时,不可能在存储桶中写入(类似于数据存储的模拟本地存储桶)。额外的困难我尝试用胖客户端的远程API在我的本地服务器上写,我在web上到处搜索都没有找到我的答案。
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/FileInfosGcsService 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();
}使用相同的代码,我可以用DataStore编写,没有任何问题,这只是一个存储问题。
发布于 2016-06-11 05:49:03
请参阅Google Cloud Storage Errors and Error Handling和Service Account文档。
403表示用户未被授权发出请求。当在您的GCE实例上运行时,我猜测您的代码运行在一个对您的存储桶具有写权限的服务帐户中。在本地运行时,您必须提供适当的凭据才能执行相同的操作。
发布于 2016-06-16 17:13:13
我明白了为什么这不起作用,实际上通过RemoteAPI调用GCS并不是写在本地服务器上,而是写在在线存储桶上。这就是为什么我没有正确的ACL,我的代码尝试连接到云存储。但是现在我不知道如何强制GCSService在我的本地服务器上写入。
https://stackoverflow.com/questions/37728287
复制相似问题