1
我首先将图片保存到Google Cloud Storage,并将MIME类型设置为“image/png”,并将其命名为“image/png”与文件结束例如“png格式”。这些文件似乎被正确存储。我可以看到他们在数据存储浏览器:无法获取来自Google云端存储的图片的服务网址 - >“NOT_IMAGE:无法读取图片”
但是,如果我尝试与com.google.appengine.api.images.ImagesService
再装回,打电话ImagesService.getServigUrl()
,它抛出的错误:
java.lang.IllegalArgumentException: NOT_IMAGE: Failed to read image
所以这似乎认为它不是一个图像。但为什么?它有MIME类型集,它有文件结尾。代码如下所示:
ImagesService imagesService = ImagesServiceFactory.getImagesService();
Image newImage = imagesService.applyTransform(crop, oldImage);
final GcsService gcsService =
GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
AppIdentityService appservice = com.google.appengine.api.appidentity.AppIdentityServiceFactory.getAppIdentityService();
GcsFilename fileName = new GcsFilename(appservice.getDefaultGcsBucketName(), Long.toString(random.nextLong(), 36)+"."+newImage.getFormat().toString().toLowerCase());
GcsFileOptions gcsOptions = new GcsFileOptions.Builder()
.mimeType("image/"+newImage.getFormat().toString().toLowerCase())
.acl("public-read").build();
GcsOutputChannel outputChannel =
gcsService.createOrReplace(fileName, gcsOptions);
ObjectOutputStream oout =
new ObjectOutputStream(Channels.newOutputStream(outputChannel));
oout.writeObject(newImage.getImageData());
oout.close();
ServingUrlOptions suo = ServingUrlOptions.Builder.withGoogleStorageFileName("/gs/"+fileName.getBucketName()+"/"+fileName.getObjectName()).secureUrl(true);
String s = imagesService.getServingUrl(suo);
System.out.println(s);
你是从Dev服务器还是Live运行你的代码? http://stackoverflow.com/questions/12868646/google-app-engine-imagesservice-getservingurl-fails-to-read-image – Ryan 2014-08-28 14:34:00
是的,它是开发服务器。但是对于另一方面的Blobstore来说,它在我的开发服务器上工作。链接的问题没有解决方案.. – jan 2014-08-28 14:59:40
如果您阅读它的评论,它说,它试图活着时,它的工作“似乎getServingUrl只能在App Engine测试服务器上失败”尝试部署它。 – Ryan 2014-08-28 15:05:19