1

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?

fnklstn
  • 492
  • 4
  • 16

1 Answers1

0

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.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • I believe it was failing because I was calling connection request again, and even though it returned the same values, the Storage for some reasons didn't recognize the file anymore. (for example, the Storage recognized file before I called request, but after request it didn't recognize - even though the name of the file was the same). – fnklstn Mar 17 '21 at 15:13