0
点赞
收藏
分享

微信扫一扫

小程序上传图片、回显、并上传到服务器

大漠雪关山月 2022-03-25 阅读 74
//选取图片
wx.chooseImage({
            count: 1,
            sizeType: ['original'],//原图
            sourceType: [ 'album','camera'],//支持选取图片
            success (res) {
                // tempFilePath可以作为img标签的src属性显示图片
                const tempFilePaths = res.tempFilePaths[0];
                //上传图片
                wx.uploadFile({
 
                    //请求后台的路径
                    url: 'http://192.168.35.201:8090/image',
 
                    //小程序本地的路径
                    filePath: tempFilePaths,
 
                    //后台获取我们图片的key
                    name: 'images',
 
                    //额外的参数formData
                    formData: {
                        'id': 'test',
                        a:{ abc:'111'},
                        b:[1,2,3]
                    },
                    success: function (res) {
                    //上传成功
                        debugger
                    },
                    fail: function (res) {
                        debugger
                    },
                })
            }
        })
举报

相关推荐

0 条评论