Blob类型下载

public static boolean dowloadToBlob(Attchment Attachment,HttpServletRequest request, HttpServletResponse response) {
try {
String filename = Attachment.getStrFileName();
byte[] fileStream = ImageUtils.blobToByte((Blob) Attachment.getStrBlob());
String userAgent = request.getHeader(“user-agent”).toLowerCase();
if (userAgent.contains(“msie”) || userAgent.contains(“like gecko”)) {
filename = URLEncoder.encode(filename, “UTF-8”);
} else {
filename = new String(filename.getBytes(“UTF-8”), “iso-8859-1”);
}
response.setContentType(“application/x-msdownload”);
response.setCharacterEncoding(“UTF-8”);
response.setHeader(“Content-Disposition”, “attachment; filename=” + filename);
OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
toClient.write(fileStream);
toClient.flush();
toClient.close();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return true;
}

猜你喜欢

转载自blog.csdn.net/weixin_44696567/article/details/93483843