在Groovy中将Base64字符串转换为图像文件

时间:2020-09-16 15:17:33

标签: image groovy base64

我检查了旧线程,但没有发现任何帮助。 我是JD Edwards开发人员,我们在jde Orchestrator中有一个要求来处理base64字符串。

任何人都可以帮助我并分享完整的代码吗?

我是groovy脚本的新手。

1 个答案:

答案 0 :(得分:0)

def base64str = 'R0lGODlhAwADAHAAACwAAAAAAwADAIHsHCT97KYAAAAAAAACBIQRBwUAOw==' // < base64 string with 3x3 gif inside
def filename = System.properties['user.home']+'/documents/my.gif'              // < filename with path

// save decoded base64 bytes into file
new File(filename).bytes = base64str.decodeBase64()

因此,您在my.gif文件夹中应该有一个新文件current user/ documents 具有3x3像素的图像(43个字节的文件)