Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chooseMedia 选择文件上传报错 #7

Open
vjzning opened this issue May 6, 2020 · 1 comment
Open

chooseMedia 选择文件上传报错 #7

vjzning opened this issue May 6, 2020 · 1 comment

Comments

@vjzning
Copy link

vjzning commented May 6, 2020

用户chooseMedia 选择视频类型的文件上传报错
image

@AsherWang
Copy link

这里也遇到同样的问题了
经查发现问题出在参数类型上
wx.chooseMedia获取到的文件大小比如res.tempFiles[0].size 的 类型是String,这点和他文档描述的不一致
wx.chooseVideo中获取到file.size的则是Number (所以使用chooseVideo的话就不会报错)
解决思路之一是手动将这个file的size值调整为Number类型

wx.chooseMedia({
  count: 1,
  mediaType: ['video'],
  sourceType: ['album', 'camera'],
  camera: 'back',
  success: function (res) {
    const file = res.tempFiles[0];
    file.size = +file.size; // 将字符串强转为数字类型
    // do sth with file
  },
})

起码在我的安卓机上可以成功上传

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants