上传图像并在 App Engine 中使用 getServingUrl() 的正确流程是什么?

What is the correct flow to upload an image and use getServingUrl() in app engine?

我有一个 android 应用程序,它希望在即时消息客户端中包含图像发送功能。我对使用 blobstore 或 google 云存储执行此操作的方式感到非常困惑。有人可以从后端的角度概述实现这一目标的步骤吗?我的目标是最终使用 getServingUrl 并有一个外部 url 供应用程序点击并获取图像。我正在使用 java 和 google 云端点。

到目前为止,我有: 1.创建上传地址 2.user 博客商店服务 .getUploads() 获取 BlobKeys 3.find 我的特定 blob 密钥(按 ID,我认为 blobs.get(ID)) 4.魔术 5. 弄清楚如何在特定的 blob 上使用 .getServingUrl(options) 6. 后端工作。

请在您的回复中包含代码或伪代码,因为我已经为此工作了好几天而且已经筋疲力尽了。我真的可以用别人来 ELI5。

我认为令人困惑的事情是尝试将它与云端点一起使用,这不是您应该做的。使用纯 Servlet(或对 Servlet 的抽象,使您可以访问 HttpServletRequest)。 使用 BlobstoreService.getUpload(HttpServletRequest):

获取 BlobKey
public void doGet(HttpServletRequest request, HttpServletResponse response) {
  BlobKey blobKey = blobstoreService.getUploads(request).get("file").get(0); // assume the form parameter was "file" and only one file was uploaded
}

并使用 ImagesService.getServingUrl(在选项构建器中设置 BlobKey)来获取 URL。

String url = imagesService.getServingUrl(ServingUrlOptions.Builder.withBlobKey(blobKey));

您可能希望将 BlobKey(使用 getKeyString)序列化到数据存储以供将来访问。