Error: Java Lang. unsupported operationexception: no image data is available when using the blobstore and image APIs of App Engine

I need to use App Engine blobstore to retrieve the height and width of the uploaded image To find me, I use the following code:

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

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

        }

I can upload an image and generate a blobkey, but when passing the blobkey to makeimagefromblob(), it will generate the following error:

How to solve this problem or any other way to find the height and width of the image directly from the blobkey

Solution

Most methods on the image itself throw unsupported operationexception

byte[] data = getData(blobKey);
Image im = ImagesServiceFactory.makeImage(data);
if (im.getHeight() == ht && im.getWidth() == wd) {}
private byte[] getData(BlobKey blobKey) {
    InputStream input;
    byte[] oldImageData = null;
    try {
        input = new BlobstoreInputStream(blobKey);
                ByteArrayOutputStream bais = new ByteArrayOutputStream();
        byte[] byteChunk = new byte[4096];
        int n;
        while ((n = input.read(byteChunk)) > 0) {
            bais.write(byteChunk,n);
        }
        oldImageData = bais.toByteArray();
    } catch (IOException e) {}

    return oldImageData;

}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>