Skip to content
Advertisement

How to give read access permission for Firestore imageurl in Java

I am able to access the Firestore image url on my browser window. I want to convert this image url into BufferedImage after reading I have to find sub-image to get barcode value presented on my image. Here is the code, I have connected with my bucket using Firestore and selecting few images from bucket based on conditions.

And rules for writing/reading is given as allow read, write: if true; in Firestore storage.

And initialized my FireBaseInitialize with key.json (service account details).

BufferedImage img = ImageIO.read(new File(imageUrl)); // imageUrl is contains path  (environment, bucket, database name)  & token

Getting below IIOException,

javax.imageio.IIOException: Can't read input file!
java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1310)

How to give read permission for images in Firestore bucket in order to read by Java ImageIO class. I am not using android version. This is specific to Java.

I suspect if permission is missing I am unable to access collection itself, correct me if I am wrong ?

Note: For testing purpose I have changed the storage permission to access to all.

rules_version = '2';
service firebase.storage {  
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}

Still getting the same error, javax.imageio.IIOException: Can’t read input file!

Advertisement

Answer

The javax.imageio.IIOException was thrown because the File class can only be instantiated with paths that are accessible through the local system, that does not include HTTP or HTTPS URIs.

Hopefully next version of Java would handle cloud things in a better way. If someone able to request for this feature from Java would be much appreciated.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement