2015-10-19 56 views
0

我能够用blobl关键服务形象 - res.sendRedirect("/serve?blob-key=" + blobKeys.get(0).getKeyString());如何使用getServingUrl获取使用Appengine ImageService的blobstore图像url?

但在Appengine Blobstore docs,提到这样的 -

注:如果提供图像,更有效的和潜在的更便宜的方法是使用App Engine Images API而不是blobstoreService.serve()来使用getServingUrl()。 getServingUrl方法可让您直接提供图像,而无需通过App Engine实例。

我想知道如何能做到这一点这里是我的代码片段 -

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()); 
} 

imageService docs here Get Serving Url Doc

+0

使用PHP而不是Java可以参考这个帖子的http://计算器.COM /问题/ 37646849 /何灿我们使用-火力点后图像文件和调整大小,它们-使用-GET-服务-URL/37673504#37673504 –

回答

1
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()); 
    }