Search code examples
androidimagepicassodrivefresco

displaying an image from drive in Android


I'm using Fresco library to display images in my Android app. I'd like to display some images (jpg or png) that I have set with public grants.

When I was doing quick tests, I just took any image from internet to set a URL, but when using the real ones that I need to use, I have the following url https://drive.google.com/uc?export=view&id=<>, but as it is a redirect and, once redirected, new url is not the image itself, Fresco is unable to display it.

I have tried Picasso as an alternative library, but with out any success.

I have also tried the download url for both libraries (https://drive.google.com/uc?export=download&id=<>). But no result.

Anybody knows how could it be possible to get this images? Or the only solution is to download it (using the second url) processing the object received store a bitmap of it and displaying it?

For downloading it, what should i use and how? retrofit?

Thanks in advance.


Solution

  • I found a solution for this problem (but could be only applicable if you use Google Cloud or Google Script).

    It consists on creating a doGet() service with the following code inside:

    var file = DriveApp.getFileById(fileId)
    return Utilities.base64Encode(file.getBlob().getBytes());
    

    and use that base64 value in your app. With this format, Fresco can do the magic

    It is not an immediate solution, and requires to do somework in other platform that is not your Android app, but it works perfectly.