小程序上传图片和视频提交到服务器-怎样给小程序上传视频-微信小程序视频上传
1.
在wxml里写好要提交的图片/视频的字段名(这里通过JS里转换为字符串在通过隐藏的input来提交)
!--课程封面--viewclass'in-demandbor-b'viewclass'dema-title'text课程封面:/text/viewviewclass'demand-coldemand-col2'viewclass'up-img'bindtap'deteleImg'data-delcover'{{idx}}'wx:for"{{imgCover}}"wx:keywx:for-index"idx"imagename'cover_course'src"{{URL}}/teacherimg/{{item}}"/image/viewviewwx:if"{{imgCover.length1}}"class'up-img'bindtap'coverCourse'src'/images/addimg.png'imagesrc'/images/addimg.png'/imageinputname"cover"style'display:none'value'{{coverImgstr}}'/input/view/view/view2.JS里data对象里添加
imgCourse:[],//课程详情 imgCover:[],//封面 tempFilePaths:[], imgCourseStr:'', coverImgstr:'',事件和方法:注释已经写得很清楚。提交的时候字段就填拼接后的coverImgstr参数就行了//选择课程详情照片courseDetail:function(e){letfielde.currentTarget.dataset.field;letthatthisletfnfunction(path){//传入path参数参数接收的是uploadImg成功后success(res.data)返回的参数console.log(path,'sssssssssss')that.data.imgCourse.push(path)//把返回的path全部添加到imgCourse数组里console.log(that.data.imgCourse,'sssssssssss')that.setData({imgCourse:that.data.imgCourse,imgCourseStr:that.data.imgCourse.join(',')//把imgCourse数组拼接为字符串方便给后台传输})}this.uploadImg().then(fn)//提交事件处理完后执行fn函数},////选择封面照片coverCourse:function(e){letfielde.currentTarget.dataset.field;letthatthisletfnfunction(path){console.log(path,'sssssssssss')that.data.imgCover.push(path)//console.log(that.data.imgCover,'sssssssssss')that.setData({imgCover:that.data.imgCover,coverImgstr:that.data.imgCover.join(',')})}this.uploadImg().then(fn)},uploadImg(){returnnewPromise((success,error){varthatthis;wx.chooseImage({count:1,//默认9sizeType:['original','compressed'],//可以指定是原图还是压缩图,默认二者都有sourceType:['album','camera'],//可以指定来源是相册还是相机,默认二者都有success:function(res){//返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片wx.uploadFile({url:CONFIG.API_URL.t_img,filePath:res.tempFilePaths[0],name:'img',success(res){success(res.data)}})}})})},//删除照片deteleImg:function(e){letdelcoursee.currentTarget.dataset.delcoures;letdelcovere.currentTarget.dataset.delcover;this.data.imgCover.splice(delcover,1);//删除封面this.data.imgCourse.splice(delcourse,1);//删除课程详情this.setData({imgCourse:this.data.imgCourse,imgCover:this.data.imgCover,})},3.
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

