Recently i was migrating an app’s backend from parse to firebase. The move to firebase’s real-time database was a breeze with minor re-factoring. I hit a block when i wanted to load images stored in firebase storage into an android Imageview. The existing code had used the excellent picasso from square for image caching and the likes. Earlier i had stored the images as blobs inside my parse database. Firebase storage has image location coming in this format. gs://appname.appspot.com/Images/1.jpg.
One option was to load the image location (http based)inside a field in the real time database and access it using picasso. This particular app had lot of images and i didn’t want to go that route. Reading through picasso’s documentation i came across picasso’s request handler. https://square.github.io/picasso/2.x/picasso/com/squareup/picasso/RequestHandler.html.
Actually the implementation was easy to code and simple enough. Below is the gist
The changes while actual loading is that you need to create a picasso instance using the builder while passing our custom request handler. Eg:
picassoInstance= new Picasso.Builder(this.activityContext.getApplicationContext())
.addRequestHandler(new FireBaseRequestHandler())
.build();
Then to load image into the imageview
picassoInstance.load(<firebasestorageurl>)
.into(imageview);
Top comments (0)