Java 如何使用getServingUrl使用Appengine ImageService获取blobstore图像url?
我能够使用blobl键提供图像-Java 如何使用getServingUrl使用Appengine ImageService获取blobstore图像url?,java,google-app-engine,Java,Google App Engine,我能够使用blobl键提供图像- res.sendRedirect(“/service?blob key=“+blobKeys.get(0.getKeyString()) 但在《基本法》中提到的是: 注意:如果您正在提供图像,一种更有效且可能更便宜的方法是使用应用程序引擎图像API使用getServingUrl(),而不是使用blobstoreService.service()。getServingUrl方法允许您直接为图像提供服务,而无需查看应用程序引擎实例 我想知道如何做到这一点,这是我的代
res.sendRedirect(“/service?blob key=“+blobKeys.get(0.getKeyString())代码>
但在《基本法》中提到的是:
注意:如果您正在提供图像,一种更有效且可能更便宜的方法是使用应用程序引擎图像API使用getServingUrl(),而不是使用blobstoreService.service()。getServingUrl方法允许您直接为图像提供服务,而无需查看应用程序引擎实例
我想知道如何做到这一点,这是我的代码片段-
Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(req);
List<BlobKey> blobKeys = blobs.get("myFile");
if (blobKeys == null || blobKeys.isEmpty()) {
res.sendRedirect("/");
} else {
res.sendRedirect("/serve?blob-key=" + blobKeys.get(0).getKeyString());
}
Map blobs=blobstoreService.getUploads(req);
List blobKeys=blobs.get(“myFile”);
if(blobKeys==null | | blobKeys.isEmpty()){
res.sendRedirect(“/”);
}否则{
res.sendRedirect(“/service?blob key=“+blobKeys.get(0).getKeyString());
}
使用PHP而不是java你可以参考这篇文章
if (blobKeys == null || blobKeys.isEmpty()) {
res.sendRedirect("/");
} else {
//todo add the user
ImagesService imagesService = ImagesServiceFactory.getImagesService();
ServingUrlOptions servingOptions = ServingUrlOptions.Builder.withBlobKey(blobKeys.get(0));
String servingUrl = imagesService.getServingUrl(servingOptions);
res.sendRedirect(servingUrl);
// res.sendRedirect("/serve?blob-key=" + blobKeys.get(0).getKeyString());
}