/**
* 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.