2012-03-18 148 views
1

我正在嘗試將數據從應用引擎應用存儲到谷歌雲存儲。使用gae將數據存儲到谷歌雲存儲中用於java

如果我這樣做本地代碼運行良好,但我沒有看到任何數據存儲。

如果我將應用程序上傳到應用程序引擎,則運行代碼時出現空指針異常: AppEngineFile writableFile = fileService.createNewGSFile(optionsBuilder.build());

使用的完整代碼IM是

 // 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

當使用開發服務,並與谷歌存儲文件服務,它實際上並沒有寫信給你的谷歌存儲桶,但到本地文件系統 - 你期待它寫入Google Storage?

對於空指針異常,需要查看堆棧跟蹤以嘗試縮小發生了什麼問題。

+1

您正在談論BlobStore「內置」服務。 Google Cloud Storage是開發環境和生產的外部服務(appspot.com) – alex 2012-03-18 11:53:50

+0

Right Alex您完美有道理。那麼關於這個問題的任何想法? – Vik 2012-03-18 16:04:44

+2

我知道 - 在應用引擎開發服務器上使用文件API時,不會讀取或寫入外部Google存儲服務,但會模仿讀取和寫入本地磁盤。 – 2012-03-18 21:34:51