[英]Base64encoding and base64decoding in dart and Java
Is base64encode and decode in dart is same for Java. In my flutter app I want to upload an image. dart 中的 base64 编码和解码是否与 Java 相同。在我的 flutter 应用程序中,我想上传一张图片。 I convert that image to string by base64Encode(file. readAsBytesSync()).
我通过 base64Encode(file.readAsBytesSync()) 将该图像转换为字符串。 And then I passed it to backend.
然后我将它传递给后端。 Backendcode is in JAVA. I want to decode this image file in java for save into a folder.
后端代码在 JAVA 中。我想在 java 中解码此图像文件以保存到文件夹中。 How it is possible.
怎么可能。 Is I decode image gives same result.?
我解码图像是否给出相同的结果。? I want to fetch it back also.
我也想取回来。 Please help
请帮忙
Putting all my comments as an answer here are 2 utility functions将我所有的评论作为答案放在这里是 2 个实用函数
public static BufferedImage decode(String base64Image)throws Exception
{
Base64.Decoder decoder=Base64.getDecoder();
ByteArrayInputStream decoded=new ByteArrayInputStream(decoder.decode(base64Image));
return ImageIO.read(decoded);
}
public static void writeImage(ByfferedImage img,File file)throws Exception
{
ImageIO.write(img,"png",file);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.