html52.com
我爱小程序-开发者交流社区

uploadFile:fail 未能链接到服务器

使用uploadFile上传图片时 在手机上 页面第一次上传都会报uploadFile:fail 未能链接到服务器  错误,第二次上传就成功了,

开发者工具上不会出现这种问题

代码如下

wx.chooseImage({

  success: function(res) {

    var tempFilePaths = res.tempFilePaths

    wx.uploadFile({

     url: `${configs.card.apiBaseUrl}api/user/upload`, // 这里是配置文件配置好的后端接口目录

      filePath: tempFilePaths[0],

      name: 'url',

      formData:{

        'user': 'test'

      },

      header: {

      token: Auth.proxy.token.access_token,

      "Content-Type": "multipart/form-data"

      },

      success: function(res){

      console.log(res)

        var data = res.data

        //do something

      },

      fail:(res)=>{

      console.log(res)  //第一次上传都会跑到 这里

      }

    })

  }

})


评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付