Glide: Load From XmlRPC Base64 String format

Created on 29 Nov 2017  路  8Comments  路  Source: bumptech/glide

Glide Version: 4.3.1

Integration libraries: com.github.piasy:GlideImageLoader

Device/Android Version: Various devices and Android versions.

Issue details / Repro steps / Use case background:

Glide load line / GlideModule (if any) / list Adapter code (if any):

Glide.with...

Layout XML:

<FrameLayout xmlns:android="...

Stack trace / LogCat:

....

I'm using odoo web api here:
https://www.odoo.com/documentation/8.0/api_integration.html

Which returns image in base64 string fomat.
I maintain decent class to handle authentication and parse response to json and finally get image field as base64. Please help I willing to using glide in such case.

question

Most helpful comment

Glad it was helpful. It should work, you can avoid the string allocation by implementing Key in OdooBinary, but that's not a big deal, especially if your users are most on ART devices (5.0+).

All 8 comments

Hi @SpiralDeveloper,

It looks like you might not have included some important information when you filed this issue. To make sure we have all the information we need to help with your issue. Please take a look at the Issue Template and make sure you've filled out as many sections as possible.
In particular you must include:

  • Glide Version
  • Glide load line
  • Issue details.

I'm marking this issue as requiring more information. Please understand that if you do not provide that information or update the issue within the next 7 days this issue will be automatically closed so that it doesn't clutter the bug tracker.
Best regards,
~ Your friendly GitIssueBot

PS: I'm just an automated script, not a human being.

Please help this is more likely request than glide issue. Thanks

You can write a custom ModelLoader that obtains the base64 string and decodes it into a byte[].

For more details on how to register custom components see http://bumptech.github.io/glide/doc/configuration.html#registering-components.

For an example ModelLoader, see any of those in Glide, ByteArrayLoader is one simple example.

can you give me sample example. I googled 'ModelLoader' all reference is outdated based on StreamModelLoader.

model

public class ImageRequest {

    public long id;
    public String model;
    public String url;
    public String name;


public static String getBase64(){
    return ...
 }

 public static byte[] getBytes(){
    return ...
  }

 }

Loader

public  class MImageLoader implements ModelLoader<ImageRequest,byte[]> {


@Nullable
@Override
public LoadData<byte[]> buildLoadData(ImageRequest imageRequest, int width, int height, Options options) {
    return null;
}

  @Override
public boolean handles(OdooImageRequest odooImageRequest) {
    return false;
     }
 }

so far this is my initial setup.. How do I process ImageRequest object and return fetched data.
`

This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

Thanks for brilliant explanation. Thank you for everything you have done.
Seriously, you saved my day. Only one very minor doubt. am I generating key correctly?

*Here is my Model *

 public class OdooBinary {
   public long id;
   public String model;
   public String column;


  private Self self;
  public OdooBinary(Self self, long id, String model, String column){
    this.self=self;
    this.id=id;
    this.model=model;
    this.column=column;
  }

public static OdooBinary dump(Self self, long id, String model, String column){
   return new OdooBinary( self,  id,  model,  column);
}

public Key diskCacheKey(){
    /*
    The combination of these is unique
     */
    return new ObjectKey(model+"_"+id+"_"+column);   //eg.   "res.partner"+"_"+50+"_"+"image_medium"
}
public String getBase64Image() throws XMLRPCException, AccessDeniedException, NetworkException, InvalidLoginException, OdooDatabaseException {
    Mapper mapper=self.env(model).read(id,column);
    return mapper.toString(column);
  }
}

`

Thank you, you are awesome.

Glad it was helpful. It should work, you can avoid the string allocation by implementing Key in OdooBinary, but that's not a big deal, especially if your users are most on ART devices (5.0+).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Tryking picture Tryking  路  3Comments

StefMa picture StefMa  路  3Comments

technoir42 picture technoir42  路  3Comments

Morteza-Rastgoo picture Morteza-Rastgoo  路  3Comments

sant527 picture sant527  路  3Comments