java - 如何在本地开发环境中从 App Engine 访问 Google Cloud Storage?

标签 java google-app-engine google-cloud-storage google-cloud-endpoints google-cloud-platform

我的代码在已部署的 Google App Engine 上运行完美,但在本地调试时却不行。返回的 GcsFileMetadata 为 null,gcsService.openReadChannel(gcsFilename, 0) 给出 FileNotFoundException,更多细节见下文。 综上所述,问题是本地应用引擎无法访问谷歌云存储。我该如何解决?请问有什么解决方法吗?

这是代码

GcsFilename gcsFilename = new GcsFilename(BUCKET_NAME, progress.imageName);

GcsFileMetadata gcsFileMetadata = gcsService.getMetadata(gcsFilename);

if (gcsFileMetadata == null) throw new Exception("gcsService.getMetadata(gcsFilename) returned null");

int fileSize = (int) gcsFileMetadata.getLength();

ByteBuffer byteBuffer = ByteBuffer.allocate(5*1024*1024);
GcsInputChannel gcsInputChannel = gcsService.openReadChannel(gcsFilename, 0);
gcsInputChannel.read(byteBuffer);

gcsFileMetadata 在本地调试时为 null,但在部署时工作正常。我将其注释掉,并在这一行收到以下错误:

GcsInputChannel gcsInputChannel = gcsService.openReadChannel(gcsFilename, 0);

这是错误:

java.io.FileNotFoundException: com.google.appengine.tools.cloudstorage.dev.LocalRawGcsService@54381103: No such file: GcsFilename(cloudimagesbucketname, image_20150105_180444)

最佳答案

没有在本地主机上访问 Google Cloud Storage 的解决方法。您必须在 appengine 部署代码,然后才能访问 GCS 服务。这是来自谷歌的安全服务,无法在本地主机上访问。

关于java - 如何在本地开发环境中从 App Engine 访问 Google Cloud Storage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27782494/

相关文章:

java - .class 我的程序的预期错误

google-app-engine - 与对象更改通知相比,Google Club Pub/Sub 的可扩展性如何

python - 谷歌云存储 Python list_blobs() 不打印对象列表

java - Caliper:如果我使用measureMemory参数运行,则出现ConfigurationException

java - 使用 HttpClient.Execute(HttpGet) 重定向后获取 URL

java - Windows 8 Maven 安装问题

python - App Engine 从 JsonProperty 返回 JSON

google-app-engine - ndb.BlobProperty 与 BlobStore : which is more private and more secure

java - 对接口(interface)的空引用如何返回值?

java - App Engine 无法下载超过 33MB 的文件