DEV Community

Premith
Premith

Posted on

2 2

How to use square‘s picasso library with firebase storage

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);

Sentry growth stunted Image

If you are wasting time trying to track down the cause of a crash, it’s time for a better solution. Get your crash rates to zero (or close to zero as possible) with less time and effort.

Try Sentry for more visibility into crashes, better workflow tools, and customizable alerts and reporting.

Switch Tools 🔁

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →