[uniapp] uniapp上传手机pdf文件

从微信小程序上传文件

上传文件

使用uni-file-picker组件上传代码

<uni-file-picker
  ref="files"
  :auto-upload="false"
  limit="9"
  file-mediatype="all"
  @select="select"
>
  <view>文件上传</view>
</uni-file-picker>
// 上传文件
select(e) {
   
  this.$refs.popup.close();
  let fullPath = e.tempFilePaths; //图片集合
  let uploadFiles = fullPath.map((item) => {
   
    return item.substring(item.lastIndexOf(".") + 1).toLowerCase(); //文件后缀小写
  });
  let typeInfo = ["pdf"];
  // 过滤出 uploadFiles 中在 typeInfo 中没有出现过的值
  const notFound = uploadFiles.filter((item) => !typeInfo.includes(item));
  if (notFound.length > 0) {
   
    uni.showToast({
   
      title: "目前仅支持pdf文件!",
      icon: "none",
      duration: 2000,
    });
    return false;
  }else{
   
	  //接口
	  //......
  }
}

在这里插入图片描述

但是这会出现上传的pdf回显在下面

在这里插入图片描述
不想让文件显示,直接把高度设置0

.is-text-box {
   
  height: 0;
}

显示文件

在这里插入图片描述
我这边是http开头的,所以需要先下载文件资源到本地才能打开

previewImage(url) {
   
  uni.downloadFile({
   
    url: url,
    success: function (res) {
   
      var filePath = res.tempFilePath;
      uni.openDocument({
   
        filePath: filePath,
      });
    },
  });
},

最后看看成果吧

在这里插入图片描述

相关推荐

  1. .PDF文件转为.DOCX文件

    2024-01-11 08:04:03       46 阅读
  2. video/pdf文件预览与进度

    2024-01-11 08:04:03       41 阅读
  3. vue2文档例子,pdf转换word例子

    2024-01-11 08:04:03       20 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-11 08:04:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-11 08:04:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-01-11 08:04:03       87 阅读
  4. Python语言-面向对象

    2024-01-11 08:04:03       96 阅读

热门阅读

  1. 【前端】html5用range型input标签怎么显示数字

    2024-01-11 08:04:03       59 阅读
  2. 前端计算精度丢失问题

    2024-01-11 08:04:03       62 阅读
  3. python实现对导入包中的全局变量进行修改

    2024-01-11 08:04:03       54 阅读
  4. ruoyi el-table调整

    2024-01-11 08:04:03       60 阅读
  5. openssl缺少libssl.so.1.1库文件

    2024-01-11 08:04:03       58 阅读
  6. metartc5_jz源码阅读-udp->receive

    2024-01-11 08:04:03       58 阅读
  7. 什么是CSS Hack

    2024-01-11 08:04:03       59 阅读
  8. 应用举例:模板方法设计模式(抽象类)

    2024-01-11 08:04:03       53 阅读
  9. Django REST框架

    2024-01-11 08:04:03       53 阅读
  10. win10使用debug,汇编初学

    2024-01-11 08:04:03       53 阅读
  11. 用汇编编写加解密函数

    2024-01-11 08:04:03       58 阅读