在速度引擎中将base64图像显示为html src

时间:2018-04-13 13:58:17

标签: java html base64 velocity

我正在为电子邮件模板使用速度,我必须发送图像的base64解码字节[]。我正在循环处理它。我可以在电子邮件中找到base64,但图像没有填充。我在下面尝试了很多案例是代码

foreach( $ele in $list)
        <tr>
            <td>$ele.getName()</td>

            <td>#set ($src = $ele.getImageBase64()) <img src="data:image/jpg;base64, $src"> 1</td>
             <td> $src</td>
            <td><img src="data:image/jpg;base64, $ele.getImageBase64()"> 2</td>
            <td><img src="data:image/jpg;base64, ${ele.getImageBase64()}"> 3</td>
            <td><img src="data:image/jpg;base64,"+$ele.getImageBase64()+"> 4</td>
        </tr>
    #end

对我来说没有任何案例可以帮助我谷歌很多,但没有得到很多帮助。任何人都可以帮助我。这里的list元素是java对象。另外base64请检查

/9j/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAAUCAAeADIEASIAAhEBAxEBBCIA/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADgQBAAIRAxEEAAA/APn+iiigD5/oooooq5ptguoXDRyX1pZRIhd57pmCqMgDAUM7EkgYVSepOACR0mneEYmj1ZZ7yxlh/spb6y1DzXSEKLuKJ5MMqvwPOXaU3Ej5VYlcgBRVzTbBdQuGjkvrSyiRC7z3TMFUZAGAoZ2JJAwqk9ScAEjpNO8IxNHqyz3ljLD/AGUt9Zah5rpCFF3FE8mGVX4HnLtKbiR8qsSuePorqP8AhB7z+0fJ/tTSvsP9n/2l/af2g/Z/s+dm77u/d5n7vZs37+Md65++tfsV5Jbi4guFXBWaB9yOpAII7jII4IDDoQCCAAcfRXUf8IPef2j5P9qaV9h/s/8AtL+0/tB+z/Z87N33d+7zP3ezZv38Y71z99a/YryS3FxBcKuCs0D7kdSAQR3GQRwQGHQgEECvRRRQBXooooooooAKKKK2PDeuf2BqMlz5c58yIxebaz+RcQ5IO6KXa2xjt2k7TlGdf4sjoL74gxancSG/0qe7hk0oaW/n6g8kzKLoTiUyEZMgAA6bdwzt2/u64eigDY8N65/YGoyXPlznzIjF5trP5FxDkg7opdrbGO3aTtOUZ1/iyOgvviDFqdxIb/Sp7uGTShpb+fqDyTMouhOJTIRkyAADpt3DO3b+7rh6K7D/AITLTvtX2f8AsD/iSf2V/Zf2T7Y3nbfN8/zfO248zzvn+5tx8u3FcvfTW895JJaWv2W34EcRkLkAADLMerHGSQAMk4CjAFeigDsP+Ey077V9n/sD/iSf2V/Zf2T7Y3nbfN8/zfO248zzvn+5tx8u3FcvfTW895JJaWv2W34EcRkLkAADLMerHGSQAMk4CjAFeiiiiigAooor/9k=

2 个答案:

答案 0 :(得分:0)

最有可能的是,您尝试显示基本64位编码的byte[]表示而不是字符串表示。

检查getImageBase64()方法的签名,看它是否返回byte[]String。如果它不是String,您就会发现问题。

如果有,请检查此转化工具是否有getImageBase64String()或类似内容。否则,您必须write it yourself

答案 1 :(得分:0)

根据文件格式检查内容类型是否正确。

示例:

data:image/jpg;base64
data:image/png;base64