【发布时间】:2012-12-21 05:57:01
【问题描述】:
在 GAE 中上传文件时,我可以使用如下代码,
//here creating a blob store service
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
//here declaring the datastore service
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
//creating entity
Entity emp = new Entity("Employee");
//set the property
emp.setProperty("First Name", fname);
emp.setProperty("Last Name", lname);
//storing the data in GAE
datastore.put(Employee);
现在,如果我需要在谷歌云存储中进行相同的文件上传,我可以设置存储桶并打开通道,如下所示,
//Creating file service
FileService fileService = FileServiceFactory.getFileService();
//setting bucket name,object name & type
GSFileOptionsBuilder optionsBuilder = new GSFileOptionsBuilder()
.setBucket(BUCKETNAME)
.setKey(FILENAME)
.setMimeType("text/html")
.setAcl("public_read")
.addUserMetadata("myfield1", "my field value");
//creating the new writable file
AppEngineFile writableFile =fileService.createNewGSFile(optionsBuilder.build());
//opening the lock and writing channel
boolean lock = false;
FileWriteChannel writeChannel = fileService.openWriteChannel(writableFile, lock);
在此之后,我不知道如何将文件存储在 Google 云存储中。我引用了这个开发人员页面Google Cloud Storage Java API Overview,但它只显示读取和写入对象而不上传文件。
请建议我将文件上传到 Google 云存储中。
感谢您的帮助。
【问题讨论】:
标签: java google-app-engine google-cloud-storage