java mail Base64 encoded string to image attachment

后端 未结 5 2064
旧巷少年郎
旧巷少年郎 2020-12-21 08:38

I have a base64 encoded string which is posted using JSON into a Spring form.

data:image/png;base64,iVBORw0KGg......etc

I want to add this

5条回答
  •  清歌不尽
    2020-12-21 09:37

    i encounter the same issue and I was able to fix it using this code:

    //you have to parse the data first to remove "data:image/png;base64" before you can use the decodeBase64(data).

    byte[] imgBytes = Base64.decodeBase64(data);
    ByteArrayDataSource dSource = new ByteArrayDataSource(imgBytes, "image/*");
    

提交回复
热议问题