SpringMvc(Base64解密)上传

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/TanZhen_1314/article/details/50350178
@RequestMapping("/upload")
@ResponseBody
public String fileUpload(HttpServletRequest request,
HttpServletResponse response) {
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(
(ServletInputStream) request.getInputStream()));
// 拿到输出流,同时重命名上传的文件
FileOutputStream os = new FileOutputStream("e:/"
+ new Date().getTime() + ".zip");
StringBuffer sb = new StringBuffer();
String line = null;
while ((line = br.readLine()) != null) {
sb.append(line);
}
System.out.println(sb.toString());
String allResult = sb.toString();
//进行解密
byte[] result = this.decodeBASE64(allResult);
os.write(result);
os.flush();
os.close();
br.close();
return "SUCCESS";
} catch (Exception e) {
e.printStackTrace();
System.out.println("上传出错");
}
return "ERROR";
}

//解密方法
//FileOutSteam写文件传byte或者int,String转byte在写文件会不成功。
public byte[] decodeBASE64(String str) throws Exception {
if (str != null) {
return new BASE64Decoder().decodeBuffer(str);
}
return null;
}
展开阅读全文

没有更多推荐了,返回首页