限时免费试用:欢迎注册 api.bigmodel.org ,快速体验大模型 API 接入服务。
当前位置:首页 >开发者 >网站框架 >小程序

小程序上传图片和视频

分类:小程序时间:2019-09-16浏览:3983

    视频
    
      
        
          添加视频
        
      
      
        
      
    
  
  
    VR图
    
      
        
          添加Vr图
        
      
      
        
      
    
  
chooseVR:function(e){
    var that = this;
    var url = config.api_base_url + "wxapp/scrz?t=2"
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths;
        wx.uploadFile({
          url,
          filePath: tempFilePaths[0],
          name: 'file',
          success(res) {
            if (res == '上传失败') {
              wx.showToast({
                title: '上传失败',
                icon: 'none',
                duration: 2000
              })
            } else {
              that.setData({
                vr_src: res.data
              })
            }
          }
        })
      }
    })
  },
  chooseVideo: function () {
    var that = this
    wx.chooseVideo({
      success: function (res) {
        console.log(res.tempFilePath)
        that.setData({
          src: res.tempFilePath,
        })
        that.uploadvideo();
      }
    })
  },
  //上传视频 目前后台限制最大100M,以后如果视频太大可以在选择视频的时候进行压缩
  uploadvideo: function () {
    var that = this
    var src = this.data.src;
    console.log(src)
    var url = config.api_base_url + "wxapp/scrz?t=2"
    wx.uploadFile({
      url: url,//服务器接口
      method: 'POST',//这句话好像可以不用
      filePath: src,
      header: {
        'content-type': 'multipart/form-data'
      },
      name: 'file',//服务器定义的Key值
      success: function (res) {
        console.log(res.data)
        console.log('视频上传成功')
        that.setData({
          v_src:res.data
        })

      },
      fail: function () {
        console.log('接口调用失败')
      }
    })
  },
本站文章如未注明出处均为原创,转载请注明出处,如有侵权请邮件联系站长。
0/500
Share your thoughts respectfully.