微信小程序> 微信小程序上传图片音频视频-微信小程序上传图片接口视频-微信小程序视频上传

微信小程序上传图片音频视频-微信小程序上传图片接口视频-微信小程序视频上传

浏览量:1561 时间: 来源:utf--8
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)})//调用上传接口}})},

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

最新资讯

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎