gpt4 book ai didi

java - 将文件写入 Blobstore AppEngine 并提供给客户端

转载 作者:行者123 更新时间:2023-12-01 15:40:23 25 4
gpt4 key购买 nike

目标:客户端将字符串输入发送到服务器 (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,请按照说明 here 操作。 .

关于java - 将文件写入 Blobstore AppEngine 并提供给客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8148224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com