按照说明操作后,AppEngine上的Google云存储中缺少java文件
我使用下面给出的说明向谷歌云存储写了一个文件:
https://developers.google.com/appengine/docs/java/googlestorage/overview
代码运行并执行成功,但是,在登录到我的存储帐户后,我在我的存储桶中没有看到新编写的文件
你知道为什么吗
这是出口代码:
This is the code I am using:
try {
// Get the file service
FileService fileService = FileServiceFactory.getFileService();
/**
* Set up properties of your new object
* After finalizing objects, they are accessible
* through Cloud Storage with the URL:
* http://storage.googleapis.com/my_bucket/my_object
*/
GSFileOptionsBuilder optionsBuilder = new GSFileOptionsBuilder()
.setBucket(bucket)
.setKey(key)
.setAcl("public-read");
// Create your object
AppEngineFile writableFile = fileService
.createNewGSFile(optionsBuilder.build());
// Open a channel for writing
boolean lockForWrite = false;
FileWriteChannel writeChannel = fileService.openWriteChannel(
writableFile, lockForWrite);
// For this example, we write to the object using the
// PrintWriter
PrintWriter out = new PrintWriter(Channels.newWriter(
writeChannel, "UTF8"));
Iterator<String> it = spRes.iterator();
while (it.hasNext()) {
out.println(it.next());
}
// Close without finalizing and save the file path for writing
// later
out.close();
String path = writableFile.getFullPath();
// Write more to the file in a separate request:
writableFile = new AppEngineFile(path);
// Lock the file because we intend to finalize it and
// no one else should be able to edit it
lockForWrite = true;
writeChannel = fileService.openWriteChannel(writableFile,
lockForWrite);
// Now finalize
writeChannel.closeFinally();
} catch (IOException e) {
result = "Failed to export";
e.printStackTrace();
}
# 1 楼答案
看起来我在谷歌云控制台中设置了两个不同的项目。我更新了错误的项目
现在可以工作了
谢谢你的帮助
# 2 楼答案
我相信您没有添加应用程序的电子邮件,您可以在appengine应用程序的应用程序设置下找到
然后,您需要在团队中的Google API Console下添加此电子邮件,以便使用is Owner权限进行谷歌云存储。确保您使用的存储桶名称与您在在线浏览器工具中为云存储创建的存储桶名称相同,该工具位于上传选项中
# 3 楼答案
正如Ankur所说,您必须在appengine上部署代码才能写入云存储。否则,文件将只存储在本地硬盘上