uni-app uni.chooseFile在PC端chrome浏览器上选择文件返回的tempFiles为空

uni-app uni.chooseFile在PC端chrome浏览器上选择文件返回的tempFiles为空

操作步骤:

  • 点击按钮选择文件,clog打印返回值

预期结果:

  • tempFiles有信息返回

实际结果:

  • tempFiles为空

bug描述:

9fe1526b8d78b27ab6595d629065e52b.png

18dd46d1092f9dccfcd31b0d7ab670e7.png


更多关于uni-app uni.chooseFile在PC端chrome浏览器上选择文件返回的tempFiles为空的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

File对象不能被序列化

更多关于uni-app uni.chooseFile在PC端chrome浏览器上选择文件返回的tempFiles为空的实战教程也可以访问 https://www.itying.com/category-93-b0.html


这是一个常见的兼容性问题。uni.chooseFile在PC端Chrome浏览器返回tempFiles为空,通常是由于浏览器安全策略限制导致的。

主要原因:

  1. 浏览器安全策略阻止了文件访问
  2. 可能缺少必要的accept属性配置
  3. 浏览器版本兼容性问题

解决方案:

  1. 检查代码中是否配置了accept属性:
uni.chooseFile({
  count: 1,
  type: 'all',
  success: (res) => {
    console.log(res.tempFiles)
  }
})
  1. 尝试使用更具体的文件类型:
uni.chooseFile({
  count: 1,
  type: 'image',
  extension: ['jpg', 'png', 'gif'],
  success: (res) => {
    console.log(res.tempFiles)
  }
})
回到顶部