我以以下格式将对象存储在Google云端存储中
bucketname/UUID/object
我有一个java方法,它以以下格式返回下载链接,以查看文件
https://storage.googleapis.com/bucket/uuid/object?GoogleAccessId
现在,我想做的是编写一个Java方法,在出现图像的情况下将调整对象的大小。这些是我的方法。
public String getResizedImage(String bucketName, String uuid, Integer size) {
GcsFilename gcsFilename = new GcsFilename(bucketName, getFileName(bucketName, uuid));
ImagesService is = ImagesServiceFactory.getImagesService();
String filename = String.format("/gs/%s/%s", gcsFilename.getBucketName(), gcsFilename.getObjectName());
return is.getServingUrl(ServingUrlOptions.Builder.withGoogleStorageFileName(filename).imageSize(size).crop(true));
}
public String getFileName(String bucketName, String uuid) {
final String[] fileName = {null};
Page<Blob> blobs = storage.list(bucketName, BlobListOption.prefix(uuid));
blobs.iterateAll().forEach(
blob -> fileName[0] = blob.getName()//.substring(blob.getName().lastIndexOf('/') + 1)
);
return fileName[0];
}
但是,当我测试getResizedImage(String bucketName, String uuid, Integer size)
时,它会引发以下错误。
com.google.apphosting.api.ApiProxy$CallNotFoundException: Can't make API call blobstore.CreateEncodedGoogleStorageKey in a thread that is neither the original request thread nor a thread created by ThreadManager
at com.google.apphosting.api.ApiProxy$CallNotFoundException.foreignThread(ApiProxy.java:800)
at com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:112)
at com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:65)
at com.google.appengine.api.blobstore.BlobstoreServiceImpl.createGsBlobKey(BlobstoreServiceImpl.java:312)
at com.google.appengine.api.images.ImagesServiceImpl.getServingUrl(ImagesServiceImpl.java:266)
at service.GoogleCloudStorage.getResizedImage(GoogleCloudStorage.java:240)
at operationstest.GoogleCloudOperationsTest.testDownloadLinkGenerationAfterResize(GoogleCloudOperationsTest.java:64)
错误发生在
return is.getServingUrl(ServingUrlOptions.Builder.withGoogleStorageFileName(filename).imageSize(size).crop(true));
我不知道是什么原因造成的。真的可以使用一些帮助。
编辑:我的解决方案尝试基于此answer。