微信小程序的文件图片上传

 今天有个需求需要上传图片,在网上查了一些资料。选择图片 wx.chooseImage已经被官方弃用,

现在的选择图片为wx.chooseMedia。

 // 选择图片 以弃用
    // wx.chooseImage({
    //   success(res) {
    //     console.log(res)
    //   }
    // })
    // 选择图片
    wx.chooseMedia({
      success(res) {
        console.log(res)
      }
    })
    // 上传图片
    wx.uploadFile({
      filePath: 'filePath', //要上传文件资源的路径 (本地路径)
      name: 'name', //文件对应的 key,开发者在服务端可以通过这个 key 获取文件的二进制内容
      url: 'http://localhost:8080/', //开发者服务器地址
    })

猜你喜欢

转载自blog.csdn.net/cx1361855155/article/details/128060647