This article describes the small program to implement the recording after the upload file method, everyone to the small program to implement the recording after uploading the file method do not know or to the small program to implement the recording after the file method of interest, then we will take a look at this article, good nonsense to get to the point!
Look directly at the code:
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); Recording failed}); }, Endrecode:function () {//end recording 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.dat A 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: ' Hint ', content:data . Message, Showcancel:false, Success:function (res) {} }); } wx.hidetoast (); }, Fail:function (res) {Console.log (res); Wx.showmodal ({title: ' Hint ', content: "Network request failed, make sure the network is OK", SHOWCANCEL:FA LSE, Success:function (RES) {}}); Wx.hidetoast (); } }); },1000)}
page Code :
<button type= "PRIMARY" bindtouchstart= "Startrecode" bindtouchend= "Endrecode" class= "cxbtn" > Press and hold recording (optional) </ Button>
Summary : After recording to delay loading, recording after the generation of files will take some time, if not delayed loading may not be able to obtain the filename prompt: Uploadfile:localid is empty
Related recommendations:
Detailed POST request in Small program development
Small program implementation drop-down loading and pull-up refresh detailed explanation