1
votes

I have an image that I loaded by using URLImage class. Here is the code:

EncodedImage placeholder = EncodedImage.createFromImage(Image.createImage(getWidth()/2, getWidth()/2 , 0xF92D2D), true);
Image originImg = URLImage.createToStorage(placeholder, imgFileName, photo_url);

To my understanding, this image is being saved into Storage with createToStorage() method. However, next time when I am loading this form, I don't want to download the image again, I want to take it from the Storage, because its faster. So what I did, I added check :

if (Storage.getInstance().exists(imgFileName)) {
        // Take the image from the Storage
    originImg = Image.createImage(Storage.getInstance().createInputStream(imgFileName));
} else {
        // Load the image with URLImage class.
}

However, it seems like my file is never saved into the Storage. What can be wrong?

1

1 Answers

0
votes

You don't need to do that. URLImage seamlessly loads the file from storage if the file is already there. You can open the network monitor and see if a request is made to the URL for this specific image.

I'm not sure why the Storage.getInstance().exists(imgFileName) method would fail. I assume the image name is different in the different execution or something of that sort. You can see that images are created in your .cn1 directory.