getServingUrl()使用Google Cloud Storage值的方法

时间:2022-08-01 15:23:02

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.

如何在不使用Blob的情况下使用getServingUrl()为图像创建基本URL?到目前为止,我见过的所有示例都涉及blob,但我需要使用Google Cloud Storage值。

Thanks.

3 个解决方案

#1


8  

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.

getServingUrl()有一个新的重载,带有ServingUrlOptions方法参数。它的构建器有一个withGoogleStorageFileName()方法,您可以使用该方法根据云存储文件名创建URL。

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:

  1. https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/images/ImagesService.html#getServingUrl(com.google.appengine.api.images.ServingUrlOptions)
  2. https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/images/ServingUrlOptions.Builder.html

#2


2  

This is an old question, but this is how you serve images from Cloud Storage:

这是一个老问题,但这是您从云存储提供图像的方式:

String key = "/gs/<bucket-name>/<path>"; // Such as /gs/example-bucket/categories/animals.png"
ImagesService imagesService = ImagesServiceFactory.getImagesService();
ServingUrlOptions options = ServingUrlOptions.Builder
                .withGoogleStorageFileName(key)
                .imageSize(900) // Optional.
                .crop(true); // Optional.
String servingUrl = imagesService.getServingUrl(options);

Then you do whatever you want with the URL. For instance, you redirect request there.

然后用URL做任何你想做的事。例如,您在那里重定向请求。

That URL may have more options than imageSize and crop but Java API provided does not seem to support it. You could, however, append additional options to the URL string but this is not a matter of GCS but rather Images API.

该URL可能比imageSize和crop有更多选项,但提供的Java API似乎不支持它。但是,您可以在URL字符串中附加其他选项,但这不是GCS的问题,而是Images API。

#3


-1  

Instead you can use PHP to do it .its more easier than JAVA /Py

相反,您可以使用PHP来实现它。比JAVA / Py更容易

how can we use firebase image file and resize them using get_Serving_URL

我们如何使用firebase映像文件并使用get_Serving_URL调整它们的大小

#1


8  

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.

getServingUrl()有一个新的重载,带有ServingUrlOptions方法参数。它的构建器有一个withGoogleStorageFileName()方法,您可以使用该方法根据云存储文件名创建URL。

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:

  1. https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/images/ImagesService.html#getServingUrl(com.google.appengine.api.images.ServingUrlOptions)
  2. https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/images/ServingUrlOptions.Builder.html

#2


2  

This is an old question, but this is how you serve images from Cloud Storage:

这是一个老问题,但这是您从云存储提供图像的方式:

String key = "/gs/<bucket-name>/<path>"; // Such as /gs/example-bucket/categories/animals.png"
ImagesService imagesService = ImagesServiceFactory.getImagesService();
ServingUrlOptions options = ServingUrlOptions.Builder
                .withGoogleStorageFileName(key)
                .imageSize(900) // Optional.
                .crop(true); // Optional.
String servingUrl = imagesService.getServingUrl(options);

Then you do whatever you want with the URL. For instance, you redirect request there.

然后用URL做任何你想做的事。例如,您在那里重定向请求。

That URL may have more options than imageSize and crop but Java API provided does not seem to support it. You could, however, append additional options to the URL string but this is not a matter of GCS but rather Images API.

该URL可能比imageSize和crop有更多选项,但提供的Java API似乎不支持它。但是,您可以在URL字符串中附加其他选项,但这不是GCS的问题,而是Images API。

#3


-1  

Instead you can use PHP to do it .its more easier than JAVA /Py

相反,您可以使用PHP来实现它。比JAVA / Py更容易

how can we use firebase image file and resize them using get_Serving_URL

我们如何使用firebase映像文件并使用get_Serving_URL调整它们的大小