您好,上传图片选择拍照方式安卓下有时候会出现问题
发布于 5 年前 作者 maoxiuying 6865 次浏览 来自 问答

采用了拍一张就自动上传的方式,可是有时候在安卓下会突然卡住,点击返回直接返回到了首页。代码如下:

upload: function () {
    var that = this
    wx.chooseImage({
        count: 9, // 默认9
        sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
        sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
        success: function (res) {
            // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
            var tempFilePaths = res.tempFilePaths
 
            for (var i = 0; i < tempFilePaths.length; i++) {
 
                wx.uploadFile({
                    url: 'https://www.xxx.com',
                    filePath: tempFilePaths[i],
                    name: 'picfiles',
                    header: {
                        'Content-Type': 'application/json',
                        'X-API-Sessionkey': wx.getStorageSync('scsessionid')
                    },
                    success: function (res) {
 
                        var upphotos = that.data.upphotos
 
                        var data = res.data
                        data = JSON.parse(data)
                        upphotos.push(data)
                    
                        that.setData({
                            upphotos: upphotos
                        })
                         
                        
                     
                    
                 
                       
                    }
                })
            }
 
        }
    })
}
1 回复

今天打开了“春雨医生”的微信小程序,上传图片选择拍照模式,也会出现问题,但偶尔又是好的。测试机型是红米Note 4

回到顶部