【发布时间】:2015-02-21 11:56:54
【问题描述】:
在客户端,我使用 Jquery 将图像从图像转换为 Base64 字符串并将其发送回服务器。在服务器上,我按原样存储字符串,并且当我很好地显示图像时,它也会在所需的页面上呈现。但是,当我在下面使用此类时,我无法将图像存储在服务器上的磁盘上,也无法使用 ImageIO.read 或使用输出流,之后它不会显示出来。
public static void saveCompanyLogo(String path,String logo,String comId){
String s[]=logo.split(";");
String format=s[0].substring(11);
File file = new File(path+"SecurePass\\logos\\");
if (!file.exists()) {
boolean result = false;
try{
File f=new File(path+"SecurePass\\logos\\");
f.mkdir();
result = true;
} catch(SecurityException se){
//handle it
}
if(result) {
}
}
byte[] b=Base64.decodeBase64(logo.replaceAll(" ", "+"));
try (OutputStream stream = new FileOutputStream(path+"SecurePass\\logos\\"+comId+"."+format)) {
stream.write(b);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
我根据溢出用户的建议使用 replaceAll,但不行。请帮忙。在上面的代码中,“logo”包含 Base64 字符串。我也使用 ImageIO.read 使用 imagereaders 但不行。数据好像有问题。
谢谢。
【问题讨论】:
标签: javascript jquery image base64 javax.imageio