Java 使用Google云存储值的getServingUrl()方法

Java 使用Google云存储值的getServingUrl()方法,java,google-app-engine,Java,Google App Engine,在不使用blob的情况下,如何使用getServingUrl()为图像创建基本URL?到目前为止,我看到的所有示例都涉及blob,但我需要使用谷歌云存储价值 谢谢。有一个带有ServingUrlOptions方法参数的getServingUrl()的新重载。它的生成器有一个withGoogleStorageFileName()方法,您可以使用该方法基于云存储文件名创建URL GcsFilename gcsFilename = new GcsFilename("bucketName", "obje

在不使用blob的情况下,如何使用getServingUrl()为图像创建基本URL?到目前为止,我看到的所有示例都涉及blob,但我需要使用谷歌云存储价值


谢谢。

有一个带有
ServingUrlOptions
方法参数的
getServingUrl()
的新重载。它的生成器有一个
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:


  • 这是一个老问题,但这是如何从云存储服务图像:

    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);
    
    String key=“/gs/”;//例如/gs/example bucket/categories/animals.png“
    ImagesService ImagesService=ImagesServiceFactory.getImagesService();
    ServingUrlOptions=ServingUrlOptions.Builder
    .withGoogleStorageFileName(键)
    .imageSize(900)//可选。
    .crop(true);//可选。
    字符串servingUrl=imagesService.getServingUrl(选项);
    
    然后,您可以对URL执行任何您想要的操作。例如,您可以在那里重定向请求


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

    URL中的/gs/会导致无URL,删除它会导致异常“Google存储文件名”s必须以/gs/'作为前缀,我应该怎么做?如果这样做,应该是相同的:ImagesService is=ImagesServiceFactory.getImagesService();String filename=String.format(“/gs/%s/%s”,“bucketName”,“objectName”);String servingUrl=is.getServingUrl(ServingUrlOptions.Builder.withGoogleStorageFileName(filename));我的意思是你不需要使用com.google.appengine.tools appengine gcs client 0.7我错了吗?我尝试了上面的代码行,我得到了以下异常-线程“main”com.google.apphosting.api.ApiProxy$CallNotFoundException中的异常:api包“blobstore”或调用“CreateEncodedGoogleStorageKey()'未找到。你知道吗?@das这似乎是一个不兼容或缺少的运行时依赖项。
    mvn依赖项:tree
    是你的朋友:D你应该查看完整的堆栈跟踪并确定它来自哪个工件。此外,尝试用谷歌搜索此函数(在大多数情况下,
    github
    query工作起来很有魅力)。找出它应该是哪个工件将帮助您确定它是否确实丢失或只是版本错误。@das我遇到了完全相同的问题。您是否设法修复了它?