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

原文链接:How to use square‘s picasso library with firebase storage

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容