当前位置: 首页 > news >正文

松阳建设局网站企业网站导航下拉菜单怎么做

松阳建设局网站,企业网站导航下拉菜单怎么做,嘉兴网站的优化,400靓号手机网站建设实现在线预览PDF文件、图片,并且预览地址不显示文件或图片的真实路径。1、vue使用blob流在线预览PDF、图片(包括jpg、png等格式)。1、按钮的方法:2、方法详细:(此方法可以在发起请求时携带token&#xff0c…

实现在线预览PDF文件、图片,并且预览地址不显示文件或图片的真实路径。

    • 1、vue使用blob流在线预览PDF、图片(包括jpg、png等格式)。
      • 1、按钮的方法:
      • 2、方法详细:(此方法可以在发起请求时携带token,适合JWT认证)
      • 3、script中定义一些指定格式使用blob转换的文件类型:
      • 4、export default 中data ( ) 设置文件类型数组包含何种文件格式:
    • 2、springboot后端接口返回文件流。(文件类型放在请求头,以便前端获取处理)
      • 1、方法1:
      • 2、方法2:
    • 3、前端最终的展示效果:

1、vue使用blob流在线预览PDF、图片(包括jpg、png等格式)。

想要实现在线预览PDF文件、图片,并且预览地址不显示文件或图片的真实路径,可使用blob流。

vue前端关键代码:

1、按钮的方法:

<el-button color="#00ffcc" size="small" @click="invoicePreview(props.row.oid)" v-if="props.row.ifInvoice == 1"><el-icon><Tickets /></el-icon>查看发票</el-button>

2、方法详细:(此方法可以在发起请求时携带token,适合JWT认证)

// 预览发票
invoicePreview(oid){console.log(oid)this.$http({url: 'invoicePreview',method: 'get',responseType: 'arraybuffer',params: {oid: oid}}).then(res => {console.log(res);console.log(res.headers.type);let fileType = res.headers.type;let currType = '';const binaryData = [];if(fileType){currType = fileTypeMap[fileType]if(this.imageType.includes(fileType)){// 识别为图片binaryData.push(res.data);//获取blob链接this.URL = window.URL.createObjectURL(new Blob(binaryData, {type: currType}));window.open(this.URL);}else if(this.wordType.includes(fileType)){// 识别为PDFbinaryData.push(res.data);//获取blob链接this.URL = window.URL.createObjectURL(new Blob(binaryData, {type: currType}));window.open(this.URL);}else {this.$message.error('不支持此文件预览')}}else {this.$message.error('不支持此文件预览')}})}

3、script中定义一些指定格式使用blob转换的文件类型:

const fileTypeMap = {"pdf": "application/pdf","png": "image/png","gif": "image/gif","jpeg": "image/jpeg","jpg": "image/jpeg","txt": "txt/plain",}

4、export default 中data ( ) 设置文件类型数组包含何种文件格式:

作用是与blob转换的文件类型进行匹配。

data () {return {wordType:['pdf', 'txt'],imageType: ['png', 'gif', 'jpeg', 'jpg']}

在这里插入图片描述

2、springboot后端接口返回文件流。(文件类型放在请求头,以便前端获取处理)

后端关键代码:(二选一即可)

1、方法1:

        File file = new File(filePath);//获取文件后缀String suffix = file.getName().substring(file.getName().lastIndexOf(".") + 1, file.getName().length());//使用流的形式下载文件--方法2try (InputStream is = new FileInputStream(filePath);OutputStream os = response.getOutputStream()) {byte[] bytes = StreamUtils.copyToByteArray(is);response.reset();response.addHeader("Content-Disposition", "inline;filename=" + new String(filePath.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1));response.addHeader("Content-Length", "" + bytes.length);// 文件类型放在请求头,以便前端获取处理response.addHeader("type", suffix);os.write(bytes);os.flush();} catch (Exception e) {e.printStackTrace();}

2、方法2:

        File file = new File(filePath);//获取文件后缀String suffix = file.getName().substring(file.getName().lastIndexOf(".") + 1, file.getName().length());try {response.addHeader("Content-Disposition", "inline; filename*=UTF-8''" + URLEncoder.encode(file.getName(), "UTF-8"));// 文件类型放在请求头,以便前端获取处理response.addHeader("type", suffix);} catch (UnsupportedEncodingException e) {e.printStackTrace();}ServletOutputStream os = null;try{os = response.getOutputStream();os.write(FileUtils.readFileToByteArray(file));os.flush();} catch (IOException e) {e.printStackTrace();}finally {if(os != null){// 此处的close为一个私有方法close(os);}}
private void close(Closeable closeable){if(closeable != null){try{closeable.close();}catch (IOException e) {e.printStackTrace();}}}

3、前端最终的展示效果:

在这里插入图片描述
在这里插入图片描述
至此完结!

http://www.15wanjia.com/news/191956.html

相关文章:

  • 潍坊网站制作怎么做网站建设技术流程图
  • 柳州网站制作推荐用dreamware做的教学网站
  • 网站开发与维护算什么职位2022年一建停考最新消息
  • 网站常见问题是什么做家教什么网站比较好
  • wordpress悬浮电话插件淘宝seo
  • 做调查问卷赚钱注册网站网店网络营销策划方案
  • 英文网站建设需要准备什么网站花瓣飘落的效果怎么做
  • 如何做网站免费推广郑州纯手工seo
  • 哈尔滨市住房与城乡建设局网站创建免费网站需要什么条件
  • 做seo推广手机网站wordpress退出维护模式
  • 企业制作网站公司广东的互联网公司有哪些
  • 网站设计重要性ui设计交付物都包含哪些
  • 一个网站每年维护费用织梦模板安装详细教程
  • 网站开发后端开发无锡阿凡达网站建设
  • 西安网站建设官网idc网站源码
  • 长沙网站排名优化价格网站建设宝安
  • 旅游网站开发注意点wordpress330
  • 广州网站开发哪家专业怎么制作免费网站教程视频
  • 高性能网站建设 下载企业宣传册免费模板网站
  • 山东信达建设有限公司网站卖东西的网站模板免费下载
  • 有源码就可以自己做H5网站吗建站平台与建站系统
  • 基于微信公众号开发网站开发wordpress 股票 插件
  • 做网站界面用什么软件公司ppt模板
  • 深圳网站建设 乐云践新宁波城乡建设局网站
  • 拟采用建站技术建设官网网站
  • 网站每天做100个外链怎么开一家网站开发公司
  • php做网站标题加链接期货软件定制开发公司
  • 网站备案好后网站怎样盈利
  • 扬州品牌网站设计设计导航网站 左侧菜单栏
  • 要找企业做网站应该注意什么wordpress 小米主题