微信小程序上传图片音频视频-微信小程序上传图片接口视频-微信小程序视频上传
1.
wxml:
buttonbindtap'imageUpload'上传图片/buttonbuttonbindtouchstart"startRecode"bindtouchend"endRecode"class"cxbtn"上传音频/buttonbuttonbindtap'videoUpload'上传视频/button2.js:
imageUpload(){varthatthis;//选择图片wx.chooseImage({count:1,sizeType:['original','compressed'],sourceType:['album','camera'],success(res){//tempFilePath可以作为img标签的src属性显示图片consttempFilePathsres.tempFilePathsthat.upImgs(tempFilePaths[0],0);}})},//上传图片upImgs:function(imgurl,index){varthatthis;wx.uploadFile({url:api.image_upload,//filePath:imgurl,name:'file',header:{'content-type':'multipart/form-data'},formData:null,success:function(res){vardataJSON.parse(res.data);vardata2JSON.parse(data.data);that.setData({picPath:data2.path})wx.showToast({title:'图片上传成功',icon:'success',duration:2000})}})},//选择音频startRecode:function(){varthatthis;console.log("start");wx.startRecord({success:function(res){console.log(res);vartempFilePathres.tempFilePath;that.setData({recodePath:tempFilePath,isRecode:true});},fail:function(res){console.log("fail");console.log(res);//录音失败}});},endRecode:function(){//结束录音varthatthis;console.log("end");wx.stopRecord();that.setData({isRecode:false});//wx.showToast();setTimeout(function(){console.log(that.data.recodePath);wx.uploadFile({url:api.audio_upload,//上传接口filePath:that.data.recodePath,name:'file',header:{'content-type':'multipart/form-data'},success:function(res){varstrres.data;vardataJSON.parse(str);if(data.states1){varcEditDatas.data.editData;cEditData.recodeIdentitydata.identitys;that.setData({editData:cEditData});}else{wx.showModal({title:'提示',content:'上传成功',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)},//选择视频videoUpload:function(){varthatthiswx.chooseVideo({sourceType:['album','camera'],maxDuration:60,camera:'back',success:function(res){that.setData({video:res.tempFilePath,size:(res.size/(1024*1024)).toFixed(2)})//调用上传接口}})},声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

