我正在尝试将数据从应用引擎应用存储到谷歌云存储。使用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");
您正在谈论BlobStore“内置”服务。 Google Cloud Storage是开发环境和生产的外部服务(appspot.com) – alex 2012-03-18 11:53:50
Right Alex您完美有道理。那么关于这个问题的任何想法? – Vik 2012-03-18 16:04:44
我知道 - 在应用引擎开发服务器上使用文件API时,不会读取或写入外部Google存储服务,但会模仿读取和写入本地磁盘。 – 2012-03-18 21:34:51