【发布时间】:2011-09-19 07:33:07
【问题描述】:
使用 ImagesService 转换上传的图片后,我想将其存储回一个新的 Blob 文件,并通过 ImagesService 提供的getServingUrl() 提供。
按照here 的描述将图像存储在新的 AppEngineFile 中工作正常,我可以使用开发服务器在本地打开和查看它。
但是,当将新 AppEngineFile 的 blobKey 传递给 ImagesService.getServingUrl() a 时
java.lang.IllegalArgumentException: 无法读取 blob。
抛出异常。任何想法可能是什么问题?这是我用来转换和存储上传图片的代码(blobKey和blobInfo对应的是上传的文件,不是新创建的)。
/* Transform image in existing Blob file */
Image originalImage = ImagesServiceFactory.makeImageFromBlob(blobKey);
Transform verticalFlip = ImagesServiceFactory.makeVerticalFlip();
ImagesService imagesService = ImagesServiceFactory.getImagesService();
Image newImage = imagesService.applyTransform(verticalFlip, originalImage);
/* Store newImage in an AppEngineFile */
FileService fileService = FileServiceFactory.getFileService();
AppEngineFile file = fileService.createNewBlobFile(blobInfo.getContentType());
FileWriteChannel writeChannel = fileService.openWriteChannel(file, true);
ByteBuffer buffer = ByteBuffer.wrap(newImage.getImageData());
writeChannel.write(buffer);
/* closeFinally assigns BlobKey to new file object */
writeChannel.closeFinally();
BlobKey newBlobKey = fileService.getBlobKey(file);
编辑:
上面的代码是正确的,问题是使用newBlobKey.toString()而不是newBlobKey.getKeyString()来存储新blob键的字符串表示。
【问题讨论】:
标签: image google-app-engine blob