上传文件(pdf,dox,ppt,xml形式的)
发布于 5 年前 作者 kpan 778 次浏览 来自 问答

求官方大神指点,小程序能上传pdf,dox,ppt,xml形式的文件吗?

2 回复

上面是代码,这个是调试器提示,怎么改啊

uploadFile:function(e){

 console.log(e);

 wx.showToast({

  title:‘加载中’,

  icon:‘loading’,

});

 var acc=wx.getStorageSync(‘account’);

 const that = this;

 wx.request({

  url: ’   ',

  data: {

    account_no: acc,

    files:e.detail.value

  },

  header: {

    “Content-Type”: “application/x-www-form-urlencoded”

  },

  method:‘POST’,

  dataType:‘json’,

  success: function (res) {

    wx.downloadFile({

      url: ’  ',

      success: function (res) {

        var filePath = res.tempFilePath

        wx.openDocument({

          filePath: filePath,

          success: function (res) {

            console.log(‘打开文档成功’)

            var tempFilePath = res.tempFilePath

            wx.uploadFile({

              url: ‘https://cibhelp.xiaohesoft.com/cibapi/monthlyplan/plan_file_upload.php’, //仅为示例,非真实的接口地址

              filePath: tempFilePath,

              name: ‘files’,

              formData:{

                ‘user’: ‘test’

              },

              success: function(res){

                var data = res.data

                //do something

              }

            })

          }

        })

      }

    })

 

    that.setData({

     upFile:res.tempFilePat         

   })

    console.log(res);

    console.log(res.data);

  }

});

 wx.hideToast();

}

回到顶部