Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Load an instance of com.smartgwt.client.widgets.Img from byte stream

    Hello,

    I persist all my data (including binary) in SQL Server database tables. On the client side, on occasion I add embedded components (images) to individual cells in a ListGrid via ListGrid.addEmbeddedComponent.

    At present I ensure that the binary data is cached on the filesystem and uniquely identifiable so that I can specify an appropriate URL which I supply to the constructor of Img, but I would much rather make an instance of Img by supplying the raw byte stream which is already available on the client side. Is this or some alternative possible?

    #2
    You can use Data URLs.
    Code:
    byte[] imageSource;
    //now point imageSource to the binary image data,
    //then Base64 encode the data and add a data url prefix.
    //in this case we assume png format
    return new String("data:image/png;base64,"+ new String(Base64.encodeBase64Chunked(imageSource)));
    This works for most reasonably modern browsers. Of course not for IE 6.0 but nobody is using that anymore, right?

    Gert

    Comment


      #3
      Hi gertvs,

      Thanks for the info, I'm just back from holidays so I'll try this out. You're kind of right about IE but unfortunately I do need to support it as well. Maybe there's an answer there as well.

      Cheers

      Alastair

      Comment

      Working...
      X