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 Cloud Storage のGoogle API コンソールの下のチームにこのメールを所有者権限で追加する必要があります。UploadOptionsの Cloud Storage 用オンライン ブラウザ ツールで作成したものと同じバケット名も使用していることを確認してください。

于 2013-03-19T06:54:55.510 に答える
1

Google Cloud Console で 2 つの異なるプロジェクトをセットアップしたようです。間違ったプロジェクトを更新していました。

今すぐ動作します。

ご協力ありがとうございました。

于 2013-03-26T03:21:39.670 に答える
0

Ankur が言ったように、コードを appengine にデプロイして Cloud Storage に書き込む必要があります。そうしないと、ファイルはローカルのハードディスクにのみ保存されます。

于 2013-03-24T04:36:51.223 に答える