Error :java.lang.UnsupportedOperationException: No image data is available when using App Engine's BlobStore and Image API

Viewed 1055

I need to retrieve the height and width of uploaded image using App Engine BlobStore. For finding that i used following code :

try {
            Image im = ImagesServiceFactory.makeImageFromBlob(blobKey);

            if (im.getHeight() == ht && im.getWidth() == wd) {
                flag = true;
            }
        } catch (UnsupportedOperationException e) {

        }

i can upload the image and generate the BlobKey but when pass the Blobkey to makeImageFromBlob(), it generate the following error:

java.lang.UnsupportedOperationException: No image data is available

How to solve this problem or any other way to find image height and width directly from BlobKey.

3 Answers

Another possibility is to make a useless transformation on the image (as rotating by 0 degree)

Image oldImage = ImagesServiceFactory.makeImageFromFilename(### Filepath ###);
Transform transform = ImagesServiceFactory.makeRotate(0);
oldImage = imagesService.applyTransform(transform,oldImage);

After that transformation, you may get width & height of the image as expected:

oldImage.getWidth();

Even if this works, this transformation influences the performance negatively ;)

Related