E企盈营销工具技术服务商 热线:4006-838-530

小寒亭区E企盈小程序程序上传视频及预览(含后台)

上传视频,图片等都是调用wx.uploadFile,后台接口都不用改。.wxmlbutton bindtap="chooseVideo"  添加视频/buttonblock wx:if="{{src != ''}}"  video src="{{src}}"/video/block

.js  Page({  data: {    src: ''  },  //选择视频  chooseVideo: function() {    var that = this    wx.chooseVideo({      success: function(res) {        that.setData({          src: res.tempFilePath,        })        that.uploadvideo();      }    })  },  uploadvideo: function() {    var src = this.data.src;    wx.uploadFile({      url: '**************/Upload', //服务器接口      filePath: src,      header: {        'content-type': 'multipart/form-data'      },      name: 'files',      success: function(res) {        console.log(res.data)      },      fail: functi开通财会用品小程序电话:4006-838-530on() {        console.log('接口调用失败')      }    })  }})

后台接口  [WebMethod(EnableSession = true)]        public void Upload()        {            //获取文件路径            HttpFileCollection files = HttpContext.Current.Request.Files;            //返回的对象初始化            object obj = null;            //获取项目路径            string sPath = System.Web.HttpContext.Current.Request.PhysicalPath;            //得到上一级路径            DirectoryInfo di = new DirectoryInfo(string.Format(@"{0}....", sPath));            string sFilePath = Path.Combine(di.FullName, "Upload", DateTime.Today.Year.ToString(), DateTime.Today.Month.ToString(), DateTime.Today.Day.ToString(), "");            //不存在路径则创建该路径            if (!Directory.Exists(sFilePath))            {                Directory.CreateDirectory(sFilePath);     开通轮椅小程序电话:4006-838-530       }            foreach (string key in files.AllKeys)            {                HttpPostedFile file = files[key];//file.ContentLength文件长度                if (string.IsNullOrEmpty(file.FileName) == false)                {                    string fileName = Path.GetFileName(file.FileName);// 原始文件名称                    string fileExtension = Path.GetExtension(fileName); // 文件扩展名                    string saveName = Guid.NewGuid().ToString() + fileExtension; // 保存文件名称                    string fileSaveAsName = string.Format(@"{0}{1}", sFilePath, saveName);//保存文件路径                    file.SaveAs(fileSaveAsName);//保存                    string sUrl = Path.Combine("Upload", DateTime.Today.Year.ToString(), DateTime.Today.Month.ToString(), DateTim开通DIY手工小程序电话:4006-838-530e.Today.Day.ToString(), saveName);//Url地址                    obj = (new { resultCode = "001", FileName = saveName, Url ="http://localhost:14146/"+sUrl });                }                else obj = (new { resultCode = "003", Message = "请选择要上传的文件!" });            }            HttpContext.Current.Response.Write(obj);        }

结果及返回数据

赞(0) 打赏
未经允许不得转载:E企盈小程序开发-热线:4006-838-530 » 小寒亭区E企盈小程序程序上传视频及预览(含后台)
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

模王系统开发

联系我们升级日志

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏