收藏
回答

wx.chooseMessageFile 选择文件后返回的文件类型一直是undefined?

wx.chooseMessageFile({
            count: 1,
            success(res) {
                // tempFilePath可以作为img标签的src属性显示图片


                var image = res.tempFiles[0];
                if (image.size > 1024 * 1024 * 200) {
                    wx.showToast({
                        title: "上传文件不能超过200M!",
                        icon: 'none',
                        duration: 2000
                    })
                    return;
                }


                wx.showLoading({
                    title: '上传中',
                })

                that.setData({
                    image: image,
                    hasImage: true,
                })


                //上传文件
                wx.uploadFile({
                    url: app.globalData.dev_url + '/pub/upload', //仅为示例,非真实的接口地址
                    filePath: that.data.image.path,
                    name: 'file',
                    timeout: 600000,
                    formData: {},
                    success(res) {
                        var res_obj = JSON.parse(res.data);
                        that.setData({
                            qrInfo: res_obj.data,
                        })


                        wx.hideLoading();
                    },
                    fail(res) {
                        console.log(res);
                        wx.showToast({
                            title: '上传失败,请重新上传',
                            icon: 'none'
                        })


                        wx.hideLoading();
                    }
                })
            }

})


无论选择什么文件返回的tempFiles中文件的type都是undefined,这是什么原因呢,求大神解答。

最后一次编辑于  2022-05-08
回答关注问题邀请回答
收藏

2 个回答

  • 阿笙
    阿笙
    2022-08-30

    您好,请问解决了吗


    2022-08-30
    有用
    回复
  • 宋佳耀
    宋佳耀
    2022-05-08
    image['type'] = res.type
    把这句删除掉应该就好了 用image.type访问
    
    2022-05-08
    有用
    回复 2
    • 曹二货🎩👓
      曹二货🎩👓
      2022-05-08
      额这个我看到了,我已经删除了,但是tempfiles里文件的type都是undefined
      2022-05-08
      回复
    • 宋佳耀
      宋佳耀
      2022-05-08回复曹二货🎩👓
      怎么打印的、有关联性的打印结果都贴出来看看
      2022-05-08
      回复
登录 后发表内容