2015-10-19 104 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()); 
    } 
相關問題