/**
* BASE64上传图片
*
* @param baseStr base64字符串
* @param imagePath 生成的图片地址
* @return
*/
public void base64ChangeImage(String baseStr, String imagePath) throws Exception {
BASE64Decoder decoder = new BASE64Decoder();
OutputStream out = null;
try {
// 解密
byte[] b = decoder.decodeBuffer(baseStr);
// 处理数据
for (int i = 0; i < b.length; ++i) {
if (b[i] < 0) {
b[i] += 256;
}
}
out = new FileOutputStream(imagePath);
out.write(b);
} catch (Exception e) {
throw new Exception("文件上传失败");
} finally {
if (out != null) {
out.flush();
out.close();
}
}
}
BASE64上传图片,byte[]上传 转File
最新推荐文章于 2024-06-20 21:14:34 发布