axios发出请求,获取后端图片文件流,中文乱码问题,急需解决,非常感谢!!

jinghaigangwan 2018-06-10 09:36:57
java代码:
@RequestMapping("/showDiagram")
// 显示流程图
public String showDiagram(HttpServletResponse response) {
OutputStream out = null;
String processInstanceId = "5001";
try {
// HttpServletResponse response = ServletActionContext.getResponse();
InputStream is = this.getDiagram(processInstanceId);
response.setContentType("image/png;charset=utf8");
out = response.getOutputStream();
out.write(getImgByte(is));
out.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.close();
} catch (Exception e) {
}
}
return null;
}

vue 代码:

greet() {
var url = '/sde/showDiagram/';
this.$axios.post(url, {
responseType:'arraybuffer',
// headers: {'Content-Type': 'multipart/form-data;charset=UTF-8'},
}).then(res => {


console.log(res.data);
// document.getElementById("imgTest").src = res.data;

})
}
...全文
2463 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
韩_师兄 2021-05-07
  • 打赏
  • 举报
回复
可以让后端使用base64编码,你在前端用base64解码
全栈达人 2021-05-04
  • 打赏
  • 举报
回复
这个问题解决了吗

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧