使用ImagesService轉換上傳的圖像後,我想將其存儲回新的Blob文件並通過0123Service提供的getServingUrl()
。爲新的Blob文件創建圖像提供URL
按照here中描述的方式將圖像存儲在新的AppEngineFile中可以正常工作,並且可以使用開發服務器在本地打開並查看它。
但是經過時的blobKey新AppEngineFile到ImagesService.getServingUrl()
一個
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鍵的字符串表示。
的imageServingUrl能夠裁剪和調整圖片說明裁剪的新形象,但imageService可以做更喜歡旋轉。因此,想法是將圖像上傳到Blob商店,旋轉它,將其存儲回Blob商店,然後創建旋轉圖像的imageServingUrl以提供不同比例的預覽。 上面的代碼實際上工作,我必須更新問題/添加一個答案。 – fivanski