[英]Writing files to the Blobstore AppEngine and serving to client
目标:客户端将字符串输入发送到服务器(App Engine)。 服务器修改输入,使用输出创建文件并将其提供给客户端。 GWT项目。
这是我的代码(服务器端和客户端)的方案,但我不知道如何将文件提供给客户端 。 每当我尝试在客户端输入任何BlobStore导入时,我在运行时会遇到错误(但在构建或编译时没有)。
将文件写入Blobstore标记为实验性文件(http://code.google.com/appengine/docs/java/blobstore/overview.html#Writing_Files_to_the_Blobstore)。 也许它还没有用呢? 你能帮我解决这个问题吗? 即使它没有使用Blob,只要满足上述目标即可。 谢谢。
ProjectServiceImpl.java
public class ProjectServiceImpl extends RemoteServiceServlet implements ProjectService
{
public String project(String input) throws IllegalArgumentException
{
String output = doSomethingWith(input);
FileService fileService = FileServiceFactory.getFileService();
AppEngineFile file = fileService.createNewBlobFile("text/plain");
boolean lock = true;
FileWriteChannel writeChannel = fileService.openWriteChannel(file, lock);
writeChannel.write(ByteBuffer.wrap("Hello world!".getBytes()));
writeChannel.closeFinally();
BlobKey blobKey = fileService.getBlobKey(file);
BlobstoreService blobService = BlobstoreServiceFactory.getBlobstoreService();
}
}
ProjectService.java
public interface ProjectService extends RemoteService {
String project(String name) throws IllegalArgumentException;
}
ProjectServiceAsync.java
public interface ProjectServiceAsync {
void project(String input, AsyncCallback<String> callback)
throws IllegalArgumentException;
}
MyProject.java:客户端
[...]
projectService.project(originalString, new AsyncCallback<String>() {
[...]
public void onSuccess(final String result)
{
BlobstoreService blobService = BlobstoreServiceFactory.getBlobstoreService();
}
});
您不能在客户端使用App Engine API(包括blobstore API)。 API仅适用于App Engine应用程序,而不适用于用户Javascript。 要提供blob,请按照此处的说明操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.