图片上传报错
发布于 7 年前 作者 juan41 8951 次浏览 来自 问答

报错信息:

VM6374:1 uploadFile:fail createUploadTask:fail Error: Invalid URL passed to App.getProxyForURL()’

upFileHandler () {

    wx.chooseImage({

        count: 1, 

        success (res) {

            const tempFilePaths = res.tempFilePaths

            wx.uploadFile({

                url: ‘’,

                filePath: tempFilePaths[0],

                name: ‘image’,

                formData: {

                    ‘imgIndex’: 0

                },

                header: {

                “Content-Type”: “multipart/form-data”  

                },

                success: function (res) {

                    var data = JSON.parse(res.data);

                }

            });

        }

    })

}

2 回复

upFileHandler () {

    wx.chooseImage({
        count: 1,
        success (res) {

            const tempFilePaths = res.tempFilePaths

           // tempFilePaths[0] -> http://tmp/wx47292e19a83b70a2.o6zAJs4K2DBooYSRIZKPzqGyX0JU.lMeMD2yX89WWf0be879ebe2af232739edf76c3432313.jpg

            wx.uploadFile({
                url: '',
                filePath: tempFilePaths[0],
                name: 'image',
                formData: {
                    'imgIndex': 0
                },
                header: {
                    "Content-Type": "multipart/form-data" 
                },
                success: function (res) {
                    var data = JSON.parse(res.data);
                }
            });
        }
    })
}

整理一下格式,在调用这个方法时,就会报错

uploadFile:fail createUploadTask:fail Error: Invalid URL passed to App.getProxyForURL()'
回到顶部