微信小程序 图片上传

微信小程序 图片上传

获得page数据

this.data.data字段

设置page数据

this.setData({
    data字段: 设置的值
})

上传文件 wx.uploadFile

注意:在微信公众平台上设置域名,否则域名访问无效

wx.uploadFile({
      filePath: that.data.imageScr,
      // 文件key名称
      name: 'img',
      url: 'https://域名',
      formData: {  
        // 附加信息
        'content': that.data.posterContent
      },
      header: {  
        "Content-Type": "multipart/form-data"  
      },
      success (res){
        that.setData({
          hasGenerateImageSrc: true,
          generateImageScr: "https://域名/" + res.data
        })
      },
      fail: function (res) {  
        wx.hideToast();  
        wx.showModal({  
          title: '错误提示',  
          content: '上传图片失败',  
          showCancel: false,  
          success: function (res) { }  
        })  
      }
    })
  }

wx.uploadFile 查看完整的失败信息

complete(res){
    console.log(res)
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值