Grails在csv和xml中嵌入图像

时间:2013-01-06 11:16:54

标签: xml image grails csv groovy

无论如何在csv和xml中有缩略图50x50?我正在使用grails。

1 个答案:

答案 0 :(得分:1)

您可以将图像转换为Base64并嵌入字节数据。这有时在css和其他媒体如数据库中完成。这是一个简单的例子......

将图像编码为CSV文件...

def csvFile = new File('my_csv.csv');  
def imageFile = new File('./images/thumbnail.png');    
String imageData = imageFile.bytes.encodeBase64().toString();

csvFile.append("${image.name}, ${imageData}"); //<-- write image name and data

解码图像也很容易......

byte[] imageBytes = imageData.decodeBase64();
imageFile = new File('./images/decoded/thumbnail.png');
imageFile.setBytes(imageBytes);