getServingUrl()使用Google Cloud Storage值的方法 [英] getServingUrl() Method using Google Cloud Storage value
本文介绍了getServingUrl()使用Google Cloud Storage值的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在不使用Blob的情况下使用getServingUrl()为图像创建基本URL?到目前为止,我看到的所有示例都涉及blob,但我需要使用Google Cloud Storage值。
谢谢。
getServingUrl()有一个新的重载,并带有
ServingUrlOptions $ c $> c>方法参数。它的构建器有一个带有GoogleStorageFileName()
方法的方法,您可以使用该方法根据云存储文件名创建一个URL。 GcsFilename gcsFilename = new GcsFilename(bucketName,objectName);
ImagesService = ImagesServiceFactory.getImagesService();
String filename = String.format(/ gs /%s /%s,gcsFilename.getBucketName(),gcsFilename.getObjectName());
String servingUrl = is.getServingUrl(ServingUrlOptions.Builder.withGoogleStorageFileName(filename));
Javadocs:
- https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/images/ImagesService.html#getServingUrl(com.google.appengine .api.images.ServingUrlOptions)
- https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/images/ServingUrlOptions.Builder.html
how would you create a basic URL for an image using getServingUrl() without using Blobs? All the examples I've seen so far involved blobs, but I need to use Google Cloud Storage value.
Thanks.
解决方案 There is a new overload for getServingUrl()
with a ServingUrlOptions
method argument. And its builder has a withGoogleStorageFileName()
method that you can use to create a URL based on the Cloud Storage filename.
GcsFilename gcsFilename = new GcsFilename("bucketName", "objectName");
ImagesService is = ImagesServiceFactory.getImagesService();
String filename = String.format("/gs/%s/%s", gcsFilename.getBucketName(), gcsFilename.getObjectName());
String servingUrl = is.getServingUrl(ServingUrlOptions.Builder.withGoogleStorageFileName(filename));
Javadocs:
- https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/images/ImagesService.html#getServingUrl(com.google.appengine.api.images.ServingUrlOptions)
- https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/images/ServingUrlOptions.Builder.html
这篇关于getServingUrl()使用Google Cloud Storage值的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文