- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我正在尝试制作一个 servlet,允许管理员上传图像,并允许任何 google 用户查看这些图像,到目前为止,我正在使用 https://developers.google.com/appengine/docs/java/blobstore/overview 上提供的程序。
当我上传图像时,它会使用很长的 blobKey 立即提供服务?并将其自身的副本存储在 local_db.bin 中
我不知道是否有任何方法可以缩短使用时的 blobkeys?例如,我想要一个画廊,显示用户上传的所有图像,但是到目前为止,我从数据库获取图像的唯一方法是调用类似的方法
res.sendRedirect("/serve?blob-key="+ blobKey.getKeyString())
但这仅适用于一张图像,我需要对每个新的 blobKey 进行硬编码,以便将其显示在单独的页面上,这也意味着当用户上传新图像时,我将必须编辑代码并添加新链接新图像?基本上我想知道的是是否有办法轻松定义存储在 local_db.bin 中的每个 blob。
任何帮助将不胜感激,请随时询问更多详细信息。
谢谢
最佳答案
我认为您正在以一种有点尴尬的方式处理您的问题。
它为您提供此 blob key 不是 Blobstore 问题。你能做的是:
这里让我向您展示(我的项目中的工作代码块):
@POST
@Consumes("multipart/form-data")
@Path("/databases/{dbName}/collections/{collName}/binary")
@Override
public Response createBinaryDocument(@PathParam("dbName") String dbName,
@PathParam("collName") String collName,
@Context HttpServletRequest request, @Context HttpHeaders headers,
@Context UriInfo uriInfo, @Context SecurityContext securityContext) {
try {
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator fileIterator = upload.getItemIterator(request);
while (fileIterator.hasNext()) {
FileItemStream item = fileIterator.next();
if ("file".equals(item.getFieldName())){
byte[] content = IOUtils.toByteArray(item.openStream());
logger.log(Level.INFO, "Binary file size: " + content.length);
logger.log(Level.INFO, "Mime-type: " + item.getContentType());
String mimeType = item.getContentType();
FileService fileService = FileServiceFactory.getFileService();
AppEngineFile file = fileService.createNewBlobFile(mimeType);
String path = file.getFullPath();
file = new AppEngineFile(path);
boolean lock = true;
FileWriteChannel writeChannel = fileService.openWriteChannel(file, lock);
writeChannel.write(ByteBuffer.wrap(content)); // This time we write to the channel directly
writeChannel.closeFinally();
BlobKey blobKey = fileService.getBlobKey(file);
} else if ("name".equals(item.getFieldName())){
String name=IOUtils.toString(item.openStream());
// TODO Add implementation
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
正如您所看到的,Blobstore 只是提供“图像”的一部分,您必须为自己创建一个 API 或其他东西,将这些图像或任何二进制数据获取到 Blobstore,包括将其文件名保存到数据存储区。
您必须做的另一件事是使用 API 或接口(interface)将其从 Blobstore 发送到客户端:
@GET
资源,其查询参数如 ?filename=whatever
这只是一个简化的示例,您必须确保保存文件名和 Blobkey,即如果需要,保存在正确的容器和用户中。
您可以直接使用 Blobstore API 和 Image API,但如果您需要进一步控制,则必须设计自己的 API。无论如何,这并不难,Apache Jersey 和 JBoss Resteasy 与 GAE 完美配合。
关于java - Google App Engine 使用 Blobkey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15704816/
Google Cloud Compute 中的 Google Compute Engine、App Engine 和 Container Engine 之间的实际区别是什么?什么时候使用什么? 有什么
我有一个在 Google App Engine 中运行的应用程序,它访问在 Google Compute Engine 中的机器上运行的服务。 Google App Engine 应用程序是该服务唯一
我们正在谷歌云中构建一个应用程序。我们使用 App Engine 作为前端,使用 Compute Engine 作为后端。在这些 Compute Engine 实例上,我正在运行一个接受特定“命令”消
我有一个现有的 GAE 应用程序(我们称之为应用程序 A)正在运行的情况,但由于非技术原因无法修改。当用户迁移到新的客户端版本时,我们需要将他们的数据从应用程序 A 迁移到新的 GAE 应用程序(我称
我正在尝试发现 App Engine 上的其他已部署服务。类似于 this文章建议。 我的代码是这样的: import ( "fmt" "net/http" "google.g
我想在我的网站上为“图像处理”事件设置服务器。如果我在 GCE 中使用“n1-standard-1”实例,GAE 中的可比功率是多少?是因为我算错了,还是同一个功率两者价格相差很大? 最佳答案 按小时
我在 Googl Compute Engine 和 Google App Engine 标准环境中的应用程序中创建了一个 VM 实例。我打算在 App Engine 中使用我的应用程序,在 Compu
我像往常一样使用 appcfg.py 更新我的应用程序,但收到一条错误消息。我试过 appcfg.py 回滚,两次尝试之间等了十分钟,但我仍然收到相同的错误消息。我该怎么办? 无法对 apps/dev
我想在 Google Compute Engine 上放置一个 Redis 服务器,并通过 AppEngine 的套接字支持与其对话。唯一的问题是似乎没有特定的防火墙规则说“此 AppEngine 应
我想知道 App Engine 和 Compute Engine 之间有什么区别。任何人都可以向我解释其中的区别吗? 最佳答案 App Engine 是一种平台即服务。这意味着您只需部署代码,平台会为
我正在编写一个在 App Engine 的 Go 运行时上运行的 Go 应用程序。 我注意到几乎所有使用 App Engine 服务(例如 Datastore、Mail 甚至 Capabilities
是否有人有在 Grid Engine/Sun Grid Engine/Son of Grid Engine 上运行 Docker 的经验,并且能够 monitor the resource used
我读了很多论坛,因为 grails app-engine 插件多年来没有更新,所以不可能将 grails 应用程序部署到谷歌应用程序引擎。当我准备放弃时,我发现使用 intellij 部署项目是可能的
当前设置, 运行 Windows Server 2012 (GCE Server 2012) 的谷歌计算引擎 运行 Debian Wheezy(GCE 服务器 Wheezy)的 Google 计算引擎
特定于基于 Docker 的部署,这两者之间有什么区别?由于 Google App Engine Flexible 现在也支持基于 Dockerfile 的部署,并且它也是完全托管的服务,因此它似乎比
我相信 Google Kubernetes Engine (GKE) 在 Google Compute Engine (GCE) 上运行。那么,在服务器管理方面使用 Google Kubernetes
TLDR;关于这个问题有任何更新吗? Google App Engine communicate with Compute Engine over internal network -- 是否可以在同
我正在尝试使用 Go SDK 为 App Engine 编写应用程序,但它似乎与单元测试有一种有趣的关系。人有written libraries左右this original, outdated一组工
在 App Engine 中,我想对在同一个 Google 云项目中创建的 Compute Engine 实例上运行的网络服务器进行 http fetch 调用,我想知道是否可以在不启用的情况下对实例
在编写 Go App Engine 标准应用程序时,过去的情况是您必须使用 App Engine SDK访问数据存储。然而,最近(从 Go 1.11 开始?),如果你只使用 Cloud Datasto
我是一名优秀的程序员,十分优秀!