1

我使用此处给出的说明向 Google Cloud Storage 写入了一个文件:

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();
        }
4

3 回答 3

3

我相信你没有添加你的应用程序的电子邮件,你可以在你的 appengine 应用程序的应用程序设置下找到。

然后,您需要将此电子邮件添加到具有所有者权限的Google API 控制台下的 Google Cloud Storage团队中。确保您使用的存储桶名称也与您在UploadOptions中的 Online Browser Tool for Cloud Storage 中创建的存储桶名称相同。

于 2013-03-19T06:54:55.510 回答
1

看起来我在 Google Cloud Console 中设置了 2 个不同的项目。我正在更新错误的项目。

现在工作。

谢谢您的帮助。

于 2013-03-26T03:21:39.670 回答
0

正如 Ankur 所说,您必须在 appengine 上部署代码才能写入云存储。否则,文件将仅存储在本地硬盘上。

于 2013-03-24T04:36:51.223 回答