2012-03-18 9 views
1

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

もしローカルコードが正常に実行されますが、格納されているデータは表示されません。

アプリをアプリケーションエンジンにアップロードすると、コード実行時にnullポインタ例外が発生します。 AppEngineFile writableFile = fileService.createNewGSFile(optionsBuilder.build());

使用して完全なコードイムは

 // 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"); 

答えて

0

問題は、アプリエンジンがクラウドストアで作成されたバケットに読み書きする権限がないことでした。

1

のdevのサービスとGoogleストレージとファイルサービスを使用している場合、それは実際にGoogleストレージバケットになく、ローカルファイルシステムへの書き込みをしないで - あなたが期待していますそれはGoogleストレージに書き込みますか?

nullポインタ例外については、何がうまくいかないかを絞り込むためにスタックトレースを参照する必要があります。

+1

あなたはBlobStoreの「組み込み」サービスについて話しています。 Google Cloud Storageは、開発環境と運用環境(appspot.com)の両方に外部サービスを提供しています – alex

+0

Right Alexは完全に理にかなっています。それで問題の考え方は? – Vik

+2

私が知っているのは、アプリエンジン開発サーバーでファイルAPIを使用しても、外部のGoogle Storageサービスの読み書きはできませんが、ローカルディスクへの読み書きと同じです。 –

関連する問題