将特定图像转换为base64字符串不正确

时间:2018-03-08 21:37:37

标签: java base64

我正在尝试使用以下代码将图像转换为base64字符串

public String base64Concert() throws Exception {
    String imageUrl = "https://www.anyhost.org/image/ThisGateway/ThisGatewayImage?imageName=IMG2975576618502471333.PNG";

    String getEncodedString = getBase64String(imageUrl);

    System.out.println("encoded String: " + getEncodedString);


}


// Image conversion

public String getBase64String(String imageUrl) throws Exception {
    byte[] imageBytes = IOUtils.toByteArray(new URL(imageUrl));
    String encodedString = DatatypeConverter.printBase64Binary(imageBytes);

    return encodedString;

}

这适用于任何其他图像,例如。 http://www.fnordware.com/superpng/pnggrad16rgb.png我将获得正确的base64字符串,我可以在html中使用它:

<div>
<p>This is a test</p>
<img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAlgAAAJYEAIAAABhlNPIAAAPTUlEQVR4nO3d0U5cRxRE0bpS/y58DHwweUEWFhCGxLEJe60nZCyLOzOy3apTp69te3ra3baH3W17vO62p8fnr++3p+df/+m799sefvqdL75+97uvfv2mP/P+nZ/t7//MFz/5qyd6vOV5b3qiL/Aq7W57erzee5W+3fN+8Kl48byf/FS89US/5VV6fgdveJW+x/P+q0/FO897w6v01hP9olfppnfwGz3vf/ipuP/xOz/7Kn3wb8Qn3sHA8/6xT8X9j68/+yrd8Lw3voPf4nm/6Kfi1fPe/rffG+/gt37eX/Z/nt/5Kn34vE8Pn3gH/+fP+6X/J/yPXqWz7W4AAADkOBACAABEne1yIAQAAAiSEAIAAESd7br/0z8EAAAAv5+EEAAAIMqBEAAAIMpSGQAAgKizTYcQAAAgSEIIAAAQpUMIAAAQJSEEAACIkhACAABEWSoDAAAQZWQUAAAgysgoAABAlIQQAAAgSocQAAAgSkIIAAAQpUMIAAAQ5UAIAAAQZWQUAAAgylIZAACAKAkhAABAlA4hAABAlIQQAAAgSocQAAAgysgoAABAlJFRAACAKAkhAABAlIQQAAAgylIZAACAKAkhAABAlA4hAABAlAMhAABA1NkuHUIAAIAgCSEAAECUpTIAAAB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AACBKhxAAACBKQggAABB1tukQAgAABBkZBQAAiDIyCgAAECUhBAAAiJIQAgAARLmYHgAAIEpCCAAAEOVACAAAEGWpDAAAQJSL6QEAAKIkhAAAAFE6hAAAAFESQgAAgCgJIQAAQJSlMgAAAFFGRgEAAKKMjAIAAERJCAEAAKJ0CAEAAKIkhAAAAFE6hAAAAFEOhAAAAFFnu3QIAQAAgiSEAAAAUZbKAAAAREkIAQAAoiSEAAAAUS6mBwAAiDIyCgAAEGVkFAAAIEpCCAAAEOViegAAgCgJIQAAQJQOIQAAQJSEEAAAIMqBEAAAIMpSGQAAgCgJIQAAQJSlMgAAAFESQgAAgCgdQgAAgCgJIQAAQJQDIQAAQJSlMgAAAFESQgAAgChLZQAAAKIkhAAAAFEOhAAAAFGWygAAAESdbTqEAAAAQRJCAACAKB1CAACAKAkhAABAlIQQAAAgylIZAACAKCOjAAAAUUZGAQAAoiSEAAAAUTqEAAAAURJCAACAKB1CAACAKAdCAACAqLNdOoQAAABBEkIAAIAoS2UAAACiJIQAAABREkIAAIAoF9MDAABEGRkFAACIMjIKAAAQJSEEAACIcjE9AABAlIQQAAAgSocQAAAgSkIIAAAQ5UAIAAAQZakMAABAlIQQAAAgylIZAACAKAkhAABAlA4hAABAlIQQAAAgyoEQAAAgylIZAACAKAkhAABAlKUyAAAAURJCAACAKB1CAACAKAkhAABA1NmmQwgAABBkZBQAACDKyCgAAECUhBAAACBKQggAABDlYnoAAIAoCSEAAECUAyEAAECUpTIAAABRLqYHAACIkhACAABE6RACAABESQgBAACidAgBAACijIwCAABEGRkFAACIkhACAABESQgBAACiLJUBAACIkhACAABE6RACAABEORACAABEne3SIQQAAAiSEAIAAERZKgMAABAlIQQAAIiSEAIAAES5mB4AACDKyCgAAECUkVEAAIAoCSEAAECUi+kBAACiJIQAAABRDoQAAABRlsoAAABESQgBAACiLJUBAACIkhACAABE6RACAABESQgBAACizjYdQgAAgCAjowAAAFFGRgEAAKIkhAAAAFESQgAAgCgX0wMAAERJCAEA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AAKKMjAIAAERJCAEAAKIkhAAAAFGWygAAAERJCAEAAKJ0CAEAAKIcCAEAAKLOdukQAgAABEkIAQAAoiyVAQAAiJIQAgAARP0FH4ZiJxiJquIAAAAASUVORK5CYII="/>

但是对于我要转换的这个特定图像,我得到一个奇怪的base64编码结果,当我把它放在Html中时不会显示

<div>
<p>This is a test</p>
<img src="data:image/png;base64, PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBUcmFuc2l0aW9uYWwvL0VOIj4KCjxIVE1MPjxIRUFEPjxUSVRMRT5BdXRoZW50aWNhdGlvbiBmYWlsZWQgLSBGZWRlcmFsIFJlc2VydmUgQmFua3M8L1RJVExFPgo8bWV0YSBuYW1lPSJyb2JvdHMiIGNvbnRlbnQ9Im5vaW5kZXgiPgo8c3R5bGU+CklOUFVUIHsKCUZPTlQtU0laRTogOHB0OyBDT0xPUjogIzAwMDAwMDsgRk9OVC1GQU1JTFk6IFZlcmRhbmEsIEFyaWFsLCBIZWx2ZXRpY2EsIHNhbnMtc2VyaWYKfQpCT0RZIHsKCUZPTlQtU0laRTogOHB0OyBDT0xPUjogIzAwMDAwMDsgRk9OVC1GQU1JTFk6IFZlcmRhbmEsIEFyaWFsLCBIZWx2ZXRpY2EsIHNhbnMtc2VyaWYKfQpURCB7CglGT05ULVNJWkU6IDhwdDsgQ09MT1I6ICMwMDAwMDA7IEZPTlQtRkFNSUxZOiBWZXJkYW5hLCBBcmlhbCwgSGVsdmV0aWNhLCBzYW5zLXNlcmlmCn0KUCB7CglGT05ULVNJWkU6IDhwdDsgQ09MT1I6ICMwMDAwMDA7IEZPTlQtRkFNSUxZOiBWZXJkYW5hLCBBcmlhbCwgSGVsdmV0aWNhLCBzYW5zLXNlcmlmCn0KU1VQIHsKCUZPTlQtU0laRTogOHB0OyBGT05ULUZBTUlMWTogVmVyZGFuYSwgQXJpYWwsIEhlbHZldGljYSwgc2Fucy1zZXJpZjsKfQpBOmxpbmsgewoJQ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wPgogICAgICAgICAgICAgICAgICAgIDxUQk9EWT4KICAgICAgICAgICAgICAgICAgICAgIDxUUiB2QWxpZ249dG9wIGFsaWduPWxlZnQ+CiAgICAgICAgICAgICAgICAgICAgICAgIDxURCBjbGFzcz1ncm91cGJveC1iYWNrZ3JvdW5kLWxpZ2h0IHdpZHRoPTEwCiAgICAgICAgICAgICAgICBoZWlnaHQ9MjA+Jm5ic3A7PC9URD4KICAgICAgICAgICAgICAgICAgICAgICAgPFREIGNsYXNzPWdyb3VwYm94LWJhY2tncm91bmQtbGlnaHQgd2lkdGg9MTAKICAgICAgICAgICAgICAgIGhlaWdodD0yMD4mbmJzcDs8L1REPgogICAgICAgICAgICAgICAgICAgICAgICA8VEQgY2xhc3M9Z3JvdXBib3gtYmFja2dyb3VuZC1saWdodCBoZWlnaHQ9MjA+Jm5ic3A7PC9URD4KICAgICAgICAgICAgICAgICAgICAgIDwvVFI+CiAgICAgICAgICAgICAgICAgICAgICA8VFIgdkFsaWduPXRvcCBhbGlnbj1sZWZ0PgogICAgICAgICAgICAgICAgICAgICAgICA8VEQgY2xhc3M9Z3JvdXBib3gtYmFja2dyb3VuZC1saWdodCB3aWR0aD0xMD4mbmJzcDs8L1REPgogICAgICAgICAgICAgICAgICAgICAgICA8VEQgY2xhc3M9Z3JvdXBib3gtYmFja2dyb3VuZC1saWdodCB3aWR0aD0xMD4mbmJzcDs8L1REPgogICAgICAgICAgICAgICAgICAgICAgICA8VEQgY2xhc3M9Z3JvdXBib3gtYmFja2dyb3VuZC1saWdodD5JZiB5b3UgZXhwZXJpZW5jZSB0cm91YmxlIGxvZ2dpbmcgaW4sIDxhIGhyZWY9Imh0dHBzOi8vd3d3LmZyYnNlcnZpY2VzLm9yZy9jb250YWN0dXMvY2NjLmh0bWwiPkNvbnRhY3QgQ3VzdG9tZXIgU3VwcG9ydDwvYT48L1REPgogICAgICAgICAgICAgICAgICAgICAgPC9UUj4KICAgICAgICAgICAgICAgICAgICAgIDxUUiB2QWxpZ249dG9wIGFsaWduPWxlZnQ+CiAgICAgICAgICAgICAgICAgICAgICAgIDxURCBjbGFzcz1ncm91cGJveC1iYWNrZ3JvdW5kLWxpZ2h0IHdpZHRoPTEwPiZuYnNwOzwvVEQ+CiAgICAgICAgICAgICAgICAgICAgICAgIDxURCBjbGFzcz1ncm91cGJveC1iYWNrZ3JvdW5kLWxpZ2h0IHdpZHRoPTEwPiZuYnNwOzwvVEQ+CiAgICAgICAgICAgICAgICAgICAgICAgIDxURCBjbGFzcz1ncm91cGJveC1iYWNrZ3JvdW5kLWxpZ2h0Pjxicj4gPGJyPiA8YnI+IDxicj4KICAgICAgICAgICAgICAgICAgICAgICAgICA8YnI+IDxicj4gPGJyPiA8YnI+IDxicj4gPGJyPiA8YnI+IDxicj4gPGJyPiA8YnI+IDxicj4KICAgICAgICAgICAgICAgICAgICAgICAgICA8YnI+IDxicj4gPGJyPiA8YnI+IDxicj4gPGJyPiA8YnI+IDwvVEQ+CiAgICAgICAgICAgICAgICAgICAgICA8L1RSPgogICAgICAgICAgICAgICAgICAgIDwvVEJPRFk+CiAgICAgICAgICAgICAgICAgIDwvVEFCTEU+CiAgICAgICAgICA8L1REPgogICAgICAgICAgPFREIHZBbGlnbj10b3AgYWxpZ249bGVmdCB3aWR0aD0iMTAwJSI+CiAgICAgICAgICAgIDx0YWJsZSBjZWxsc3BhY2luZz03IGNlbGxwYWRkaW5nPTAgd2lkdGg9IjEwMCUiIGJvcmRlcj0wPgogICAgICAgICAgICAgIDx0cj4KICAgICAgICAgICAgICAgICAgICAgIDx0ZCBub3dyYXA+IDxTUEFOIGNsYXNzPWhlYWRlci1wYWdlPkZpbmFuY2lhbCBTZXJ2aWNlczwvU1BBTj48QlI+CiAgICAgICAgICAgICAgICAgICAgICAgIDxTUEFOIGNsYXNzPWhlYWRlci10b3BpYz5GZWRMaW5lPEZPTlQgZmFjZT0iQXJpYWwsIEhlbHZldGljYSwgc2Fucy1zZXJpZiIKICAgICAgICAgICAgICAgICAgc2l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G1heSByZXN1bHQgaW4gY2l2aWwKICAgICAgICAgICAgICAgICAgICAgICAgICBhbmQvb3IgY3JpbWluYWwgcHJvc2VjdXRpb24uIFVzZXJzIGV4cHJlc3NseSBjb25zZW50IHRvIGhhdmluZwogICAgICAgICAgICAgICAgICAgICAgICAgIHRoZWlyIGFjdGl2aXRpZXMgbW9uaXRvcmVkLCByZWNvcmRlZCBhbmQgc2hhcmVkIHdpdGggdGhpcmQgcGFydGllcy4KICAgICAgICAgICAgICAgICAgICAgICAgICBCeSB5b3VyIGNvbnRpbnVlZCB1c2Ugb2YgdGhpcyBuZXR3b3JrLCB5b3UgYWNrbm93bGVkZ2UgdGhhdAogICAgICAgICAgICAgICAgICAgICAgICAgIHlvdSBoYXZlIHJlYWQsIHVuZGVyc3Rvb2QsIGFuZCBhZ3JlZSB3aXRoIHRoaXMgd2FybmluZyBtZXNzYWdlLjwvc3Bhbj4KICAgICAgICAgICAgICAgICAgICAgICAgICA8L3A+CiAgICAgICAgICAgICAgICAgICAgICAgIDxwPiZuYnNwOzwvcD4KICAgICAgICAgICAgICAgICAgICAgICAgPHA+Jm5ic3A7PC9wPgogICAgICAgICAgICAgICAgICAgICAgICA8cD4mbmJzcDs8L3A+CiAgICAgICAgICAgICAgICAgICAgICAgIDxwPiZuYnNwOzwvcD4KICAgICAgICAgICAgICAgICAgICAgICAgPHA+Jm5ic3A7PC9wPgogICAgICAgICAgICAgICAgICAgICAgICA8L3RkPgogICAgICAgICAgICAgIDwvdHI+CiAgICAgICAgICAgIDwvdGFibGU+CiAgICAgICAgICAgICAgICA8L1REPgogICAgICAgIDwvVFI+PC9UQk9EWT48L1RBQkxFPjwvVEQ+PC9UUj4KICA8VFI+CiAgICA8VEQ+CiAgICAgIDxUQUJMRSBjZWxsU3BhY2luZz0yIGNlbGxQYWRkaW5nPTAgd2lkdGg9IjEwMCUiIGJvcmRlcj0wPgogICAgICAgIDxUQk9EWT4KICAgICAgICA8VFI+CgogICAgICAgICAgICA8VEQgQ0xBU1M9IkZPT1RFUiI+VHJhZGVtYXJrcyBhbmQgc2VydmljZSBtYXJrcyBvbiB0aGlzIHNpdGUgbWF5IGJlIG93bmVkIGJ5IEZlZGVyYWwgUmVzZXJ2ZSBCYW5rcyBvciBvdGhlciBlbnRpdGllcy4gQSBjb21wbGV0ZSBsaXN0IG9mCiAgICAgICAgICAgIAltYXJrcyBvd25lZCBieSB0aGUgRmVkZXJhbCBSZXNlcnZlIEJhbmtzIGlzIGF2YWlsYWJsZSBhdCB3d3cuZnJic2VydmljZXMub3JnLiBQYWdlcyBvbiB0aGlzIHNpdGUgbWFya2VkIChQREYpIHJlcXVpcmUgdGhlIHVzZSBvZiB0aGUgQWRvYmU8c3VwPq48L3N1cD4KICAgICAgICAgICAgICAgIEFjcm9iYXQ8c3VwPq48L3N1cD4gUmVhZGVyPHN1cD6uPC9zdXA+IDkgb3IgaGlnaGVyICh3d3cuYWRvYmUuY29tKS48L1REPgogICAgICAgICAgICA8L1RSPgogICAgICAgICAgICA8VFI+CiAgICAgICAgICAgICAgPFREIGNsYXNzPWZvb3RlciBhbGlnbj0iY2VudGVyIj4KICAgICAgICAgICAgICAgIDxicj4KCQkJCTxTUEFOIGNsYXNzPWZvb3RlclRleHRCbGFjaz5Db3B5cmlnaHQgqSA8c2NyaXB0PmRvY3VtZW50LndyaXRlKG5ldyBEYXRlKCkuZ2V0RnVsbFllYXIoKSk8L3NjcmlwdD4gRmVkZXJhbCBSZXNlcnZlIEJhbmtzLiBBbGwgcmlnaHRzIHJlc2VydmVkLjwvU1BBTj4KICAgICAgICAgICAgICA8L1REPgogICAgICAgICAgICA8L1RSPjwvVEJPRFk+PC9UQUJMRT48L1RSPjwvVEJPRFk+PC9UQUJMRT4KCQk8L2Zvcm0+CjwvQk9EWT48L0hUTUw+Cg=="/>

我使用此在线工具https://www.base64-image.de/生成的内容验证了我从Java代码获得的结果,结果不一样。当我把它放在html中时,该工具的结果确实有用。

不幸的是,我使用的图像是使用证书保护的,因此我将无法共享该URL。 该文件大约是16MB,但我不确定大小是否是问题。还有什么我可以尝试的吗?

1 个答案:

答案 0 :(得分:1)

看起来我正在使用Resttemplate进行初始调用以获取响应中的图像URL。我在此resttemplate调用中包含了.pfx证书。但是,当我使用新的URL()进行第二次调用时,我没有包含证书,我正在检索我编码的失败的html响应。