[英]Not able to upload files from GAE project to Google cloud Storage using GCS Client library+java
[英]Storing data to google cloud storage using gae for java
我正在尝试将数据从App Engine应用程序存储到Google Cloud Storage。
如果我在本地执行,代码可以正常运行,但是我看不到任何存储的数据。
如果我将应用程序上传到应用程序引擎,则在以下位置运行代码时会得到空指针异常: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");
在Google Storage中使用dev服务和文件服务时,它实际上不会写入Google Storage存储桶,而是写入本地文件系统-您是否希望它写入Google Storage?
对于空指针异常,需要查看堆栈跟踪以尝试缩小问题范围。
因此,问题在于应用程序引擎无权读取/写入云存储中创建的存储桶。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.