-
19 Apr 2012 4:08 AM #1
Unanswered: Cannot use data:image/png;base64 in XTemplate
Unanswered: Cannot use data:image/png;base64 in XTemplate
Hi !
I try to use XTemplate and insert a Base64 image in HTML.
So i wrote :
<img src="{image.base64}"/>
With base64 = data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==
But the image won't be displayed
-
19 Apr 2012 10:54 AM #2
You probably added it as a String, use a SafeUri instead. See the source for the example at http://www.sencha.com/examples-dev/#...Place:combobox
Code:interface ComboBoxTemplates extends XTemplates { @XTemplate("<img width=\"16\" height=\"11\" src=\"{imageUri}\"> {name}") SafeHtml country(SafeUri imageUri, String name); @XTemplate("<div qtip=\"{slogan}\" qtitle=\"State Slogan\">{name}</div>") SafeHtml state(String slogan, String name); }
-
20 Apr 2012 4:18 AM #3
Thx for answer me
I try it and I receive a new error :
SafeUri can only be used as the entire value of a URL attribute. Did you mean to use java.lang.String or SafeHtml instead?
-
20 Apr 2012 4:47 AM #4
Please show the actual code you are writing, wrapped in a simple, standalone entrypoint so others can try it - it is difficult to debug a project just from an error message.
-
20 Apr 2012 5:38 AM #5
I have fixed my problem

You had right, i replace the String argument by a SafeUri argument.
view.setCell(new SimpleSafeHtmlCell<Image>(new AbstractSafeHtmlRenderer<Image>() {
@Override
public SafeHtml render(Image object) {
return r.renderItem(UriUtils.fromTrustedString(object.getBase64()),object.getName(), style);
}
}));
And
@FormatterFactories(@FormatterFactory(factory = ShortenFactory.class, name = "shorten"))
interface Renderer extends XTemplates {
@XTemplate("<img width=\"100\" height=\"100\" src=\"{base64}\"> {name}")
public SafeHtml renderItem(SafeUri base64, String name, Style style);
}
It works, thanks a lot !


Reply With Quote