1

アプリ エンジン アプリから Google クラウド ストレージにデータを保存しようとしています。

ローカルで実行すると、コードは正常に実行されますが、保存されているデータは表示されません。

アプリをアプリ エンジンにアップロードすると、次のコードの実行時に null ポインター例外が発生します。

私が使用している完全なコードは

        // 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://commondatastorage.googleapis.com/my_bucket/my_object
         */
        GSFileOptionsBuilder optionsBuilder = new GSFileOptionsBuilder()
          .setBucket("blood")
          .setKey("1234567")
          .setAcl("public-read")
          .setMimeType("text/html");//.setUserMetadata("date-created", "092011", "owner", "Jon");


        // Create your object
        AppEngineFile writableFile = fileService.createNewGSFile(optionsBuilder.build());

        // Open a channel for writing
        boolean lockForWrite = true; // Do you want to exclusively lock this object?
        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"));
        out.println("The woods are lovely and deep.");
        out.println("But I have promises too keep.");

        // Close the object without finalizing.
        out.close();

        // Finalize the object
        writeChannel.closeFinally();
        System.out.println("Completed writing to google storage");
4

2 に答える 2

1

Google Storage で開発サービスとファイル サービスを使用する場合、実際には Google Storage バケットではなく、ローカル ファイル システムに書き込みます。Google Storage に書き込むことを期待していますか?

ヌル ポインター例外の場合は、スタック トレースを確認して、問題の原因を絞り込む必要があります。

于 2012-03-18T09:04:21.613 に答える
0

つまり、アプリ エンジンがクラウド ストアで作成されたバケットへの読み取り/書き込みを許可されていないという問題がありました。

于 2012-03-20T22:35:43.280 に答える