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

学校网站建设招标公告推广公司主要做什么

学校网站建设招标公告,推广公司主要做什么,教人做网站的视频,天河区营销型网站建设实现在线预览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.shuangfujiaoyu.com/news/55562.html

相关文章:

  • wordpress主题 芯片杭州网络推广网络优化
  • 抓取网站访客数据原理营销策略手段有哪些
  • 网站做seo多少钱个人推广app的妙招
  • 安阳网站公司哪家好成都网站seo收费标准
  • 最佳的搜索引擎网站优化推广排名
  • 玩具公司网站开发论文网络推广服务费
  • 网站建设 cn旅游seo整站优化
  • 做网站用什么ui美观市场seo是什么意思
  • wp怎么做双语网站网站的营销策略
  • 霸州做网站1766534168企业培训系统app
  • 做网站需要什么配置的笔记本今日国内新闻大事20条
  • 做网站的问卷调查全球搜官网
  • 广西住房和城乡建设厅培训中心网百度seo快速排名优化软件
  • 通用网站后台管理系统(php版)互联网营销师培训
  • 软件开发工具名词解释廊坊网站建设优化
  • 域名访问网站下简述企业网站如何推广
  • appserv做网站教程电工培训内容
  • 肥城网站建设广东今天新闻最新消息
  • app源码开发公司seo排名赚官网
  • 交通建设监理协会网站百度怎么转人工客服
  • 购物网站数据分析百度电话客服24小时人工
  • 19互动网站建设关键词优化的建议
  • 蚌埠市做网站俄罗斯搜索引擎yandex推广入口
  • 全国建设项目竣工验收公示网站网站模板购买
  • 北京住建委网站开发适配问题百度百科查询
  • 淘宝联盟填网站备案seo包年优化平台
  • 网站自动售卡怎么做优优群排名优化软件
  • 用什么做网站百度搜索引擎下载
  • 粉红色主题 模板 网站 在线预览百度推广和优化有什么区别
  • 江门网站推广技巧广东seo推广贵不贵