Google app engine ImagesService.getServingUrl失败,出现IllegalArgumentException,并且没有云存储对象的错误消息
代码如下:Google app engine ImagesService.getServingUrl失败,出现IllegalArgumentException,并且没有云存储对象的错误消息,google-app-engine,Google App Engine,代码如下: public static String getNotFoundUrl(int size) { try { BlobKey blob_key = BLOB_STORE.createGsBlobKey("/gs/web_content/placeholder_img.png"); // Simple Test to make sure blob_key points at the right thing. byte[] image_data = BLOB_
public static String getNotFoundUrl(int size) {
try {
BlobKey blob_key = BLOB_STORE.createGsBlobKey("/gs/web_content/placeholder_img.png");
// Simple Test to make sure blob_key points at the right thing.
byte[] image_data = BLOB_STORE.fetchData(blob_key, 0, 100);
Application.getLogger().warning(new String(image_data));
// This parts works and gets the first 100 bytes.
ServingUrlOptions opts = ServingUrlOptions.Builder.withBlobKey(blob_key);
if(size > 0) opts.imageSize(size);
return IMAGES_SERVICE.getServingUrl(opts);
} catch(IllegalArgumentException e) {
Application.getLogger().warning("Unable to serve placeholder image from Cloud Storage.");
Application.getLogger().warning(e.getMessage());
Application.logException(e);
return "/placeholder_img.png";
}
}
我也尝试过使用
ServingUrlOptions.Builder.withGoogleStorageFileName
得到了同样的结果
在我看来,blob_键绝对有效,因为我能够使用
BlobstoreService.fetchData
读取前100个字节,它不会引发异常,并且正在成功读取数据
与其他情况不同的是,我尝试访问的文件是通过云控制台Web UI上传的,而不是通过AppEngine SDK上传的。问题在于权限。请确保您的应用程序对您尝试访问的云存储项目具有权限