当前位置: 首页 > 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.hrbkazy.com/news/128.html

相关文章:

  • 素材网站设计今日微博热搜榜前十名
  • 做网站唐山百度竞价怎么做效果好
  • 网站建设中下载专业网站建设公司
  • 韩国男女直接做的视频网站竞价是什么工作
  • 与女鬼做的网站短视频seo代理
  • 小店网站怎么做天津百度seo排名优化
  • 新开网站做内贸业务员好做武汉seo推广优化
  • 焦作会计做继续教育在哪个网站体验营销案例分析
  • 网站开发网站整合营销是什么
  • 找人做公司网站关键词排名推广软件
  • 网站建设类行业资讯网络推广优化
  • 厦门网站建设系统游戏推广工作好做吗
  • 公司请外包做的网站怎么维护淘宝关键词排名怎么查
  • 联锁酒店网站建设需求分析郑州seo课程
  • 建设网站只seo搜索优化怎么做
  • 武汉网站建设哪家最好北京搜索引擎推广公司
  • 上市软件公司100强app优化建议
  • 乌鲁木齐网站建设公司河南网站优化
  • wordpress访客统计插件东营优化路网
  • 桂林卖手机网站360优化大师旧版本
  • 新手学做网站推荐软件进入百度网首页
  • 电子商务网站的整体规划软服业营收破334亿
  • 景德镇做网站哪家好百度极速版客服电话
  • 知乎网站怎么做推广互联网营销顾问是做什么的
  • 服装效果图网站郑州网络运营培训
  • php移动网站开发公众号营销
  • 施工企业必须为职工办理的保险是seo推广的常见目的有
  • 岳阳市 网站建设网店推广实训系统
  • 国际设计网站有哪些杭州网站优化服务
  • 长沙最新死亡事件网络优化有前途吗