您好,欢迎访问一九零五行业门户网

微信小程序实现录音后上传文件方法详细

本篇文章讲述了微信小程序实现录音后上传文件方法,大家对微信小程序实现录音后上传文件方法不了解的话或者对微信小程序实现录音后上传文件方法感兴趣的话那么我们就一起来看看本篇文章吧, 好了废话少说进入正题吧!
直接看代码:
startrecode:function(){ var s = this; console.log("start"); wx.startrecord({ success: function (res) { console.log(res); var tempfilepath = res.tempfilepath; s.setdata({ recodepath: tempfilepath, isrecode:true}); }, fail: function (res) { console.log("fail"); console.log(res); //录音失败 } }); }, endrecode:function(){//结束录音 var s = this; console.log("end"); wx.stoprecord(); s.setdata({ isrecode: false }); wx.showtoast(); settimeout(function () { var urls = app.globaldata.urls + "/web/upvoice"; console.log(s.data.recodepath); wx.uploadfile({ url: urls, filepath: s.data.recodepath, name: 'file', header: { 'content-type': 'multipart/form-data' }, success: function (res) { var str = res.data; var data = json.parse(str); if (data.states == 1) { var ceditdata = s.data.editdata; ceditdata.recodeidentity = data.identitys; s.setdata({ editdata: ceditdata }); } else { wx.showmodal({ title: '提示', content: data.message, showcancel: false, success: function (res) { } }); } wx.hidetoast(); }, fail: function (res) { console.log(res); wx.showmodal({ title: '提示', content: "网络请求失败,请确保网络是否正常", showcancel: false, success: function (res) { } }); wx.hidetoast(); } }); },1000) }
页面代码:
<button type="primary" bindtouchstart="startrecode" bindtouchend="endrecode" class="cxbtn">按住录音(可选)</button>
总结:录音后要延迟加载,微信录音后生成文件需要一段时间,如果不延迟加载可能无法获取到文件名 提示:uploadfile:localid is empty
相关推荐:
微信小程序开发中的post请求详解
微信小程序实现下拉加载和上拉刷新详细讲解
以上就是微信小程序实现录音后上传文件方法详细的详细内容。
其它类似信息

推荐信息