Home > Article > Backend Development > Detailed method of uploading files after recording in WeChat applet
This article describes the method of uploading files after recording in the WeChat applet. If you don’t know about the method of uploading files after recording by the WeChat applet, or you are confused about the method of uploading files after recording by the WeChat applet. If you are interested, let’s take a look at this article together. Okay, without further ado, let’s get to the point!
Look at the code directly:
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) }
Page code:
<button type="primary" bindtouchstart="startRecode" bindtouchend="endRecode" class="cxbtn">按住录音(可选)</button>
Summary: It is necessary to delay loading after recording. It takes a while to generate the file after WeChat recording. If you do not delay loading, you may not be able to obtain the file name. Tip: uploadFile: localid is empty
Related recommendations:
WeChat appletPost request under developmentDetailed explanation
WeChat Mini Program Detailed explanation of how to implement pull-down loading and pull-up refresh
The above is the detailed content of Detailed method of uploading files after recording in WeChat applet. For more information, please follow other related articles on the PHP Chinese website!