小程序读取图片文件上传到云函数进行安全检验非常慢?
发布于 5 年前 作者 juanlong 5340 次浏览 来自 问答

使用chooseImage读取图片文件,真机上非常的慢,看到打的log已经readFile出数据了,但是接下来是调用云函数都没调用,在云函数里根本没看到被调用。

在开发工具上是可以,但是也不是很快。

有没有人知道怎么解决这个问题?谢谢

4 回复
  let that = this;
//让用户选择或拍摄照片
        wx.chooseImage({
            count: 9,
            sizeType: ['original', 'compressed'],
            sourceType: ['album'],
            success(res) {
                console.log(res)
                const tempFiles = res.tempFiles

                for (let index = 0; index < tempFiles.length; index++) {
                    // 如果文件大于1M
                    if (tempFiles[index].size > 1024 * 1000) {
                        wx.showToast({
                            title: '大于1M的图片已被去除',
                            icon: 'none',
                        });
                        continue
                    }
                    const file = tempFiles[index].path;
                    console.log('file', file)

                    wx.getFileSystemManager().readFile({
                        filePath: file,
                        success: res => {
                            console.log('readFile', res)
                            let imgBuffer = res.data

                            // 图片安全检测
                            wx.cloud.callFunction({
                                name: 'checkImage',
                                data: {
                                    imgBuffer: imgBuffer
                                }
                            }).then(res => {
                                console.log('检测结果', res)
                                
                            })
                        }
                    })

                }

            }
        })

你自查吧,我这边速度正常,

这么讲,大家都不明白的。没代码,没环境。

云调用没起效,去看文档。

chooseimage这个是不是你自己的网速特别导致上传慢?

回到顶部