【问题标题】:File missing in Google Cloud Storage on AppEngine after following instructions按照说明操作后,AppEngine 上的 Google Cloud Storage 中缺少文件
【发布时间】:2013-03-19 04:10:40
【问题描述】:

我使用此处提供的说明将文件写入 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();
        }

【问题讨论】:

  • 考虑添加您的实际代码、执行代码的方式以及如何配置 GCS 和 App Engine 之间的访问控制。
  • 在本地环境中,这将存储在 _BlobInfo_ 实体下。

标签: java google-app-engine google-cloud-storage


【解决方案1】:

我认为您没有添加您的应用程序的电子邮件,您可以在您的 appengine 应用程序的Application Setting 下找到它。

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

【讨论】:

  • 可能还想补充一点,如果 OP 在开发服务器上运行,文件实际上并没有上传。
  • 我猜它仍然无法正常工作。我在 Google Cloud Storage 的 Google API 控制台下添加了我团队的电子邮件地址,并以“是所有者”作为特权。如果可以的话,我会附上一张快照。
  • 我想我没有发布图片的权限。我可以随时将快照通过电子邮件发送给你们或发布到某个地方。
  • 您一定遗漏了一些东西,因为我已经有一个应用程序以类似的方式运行。请记住,它不会在本地运行。如果你愿意,我也可以分享我的代码。
  • 感谢 Ankur。在这一点上,我不确定我错过了什么。我相信代码不是问题,它更像是谷歌云存储帐户的设置......
【解决方案2】:

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

现在工作。

感谢您的帮助。

【讨论】:

    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-05
      • 2014-08-30
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 2015-07-07
      • 1970-01-01
      相关资源
      最近更新 更多