微信小程序> 微信小程序上传图片到七牛融合CDN

微信小程序上传图片到七牛融合CDN

浏览量:520 时间: 来源:徐梓枭

1.引入包

下载地址: http://7xvilo.com1.z0.glb.clouddn.com/qiniu-wxapp-sdk-master.zip

2.初始化七牛

const qiniuUploader  = require("../../state/qiniuUploader.js");// 初始化七牛相关参数function initQiniu(that) {  var options = {    uploadURL:"https://up-z1.qbox.me",//根据区域找地址    region: 'NCN', // 华北区    uptoken: that.data.qiniuToken,//token由后端接口获取后的token值,其他方法参考文档    domain: 'http://phq1b7zvy.bkt.clouddn.com/',    shouldUseQiniuFileName: false  };  qiniuUploader.init(options);}

3.上传操作

chooseImage:function(e){    var that=this;    //初始化七牛    initQiniu(that);    console.log()    // 微信 API 选文件    wx.chooseImage({      count: 1,      success: function (res) {        var filePath = res.tempFilePaths[0];        // 交给七牛上传        qiniuUploader.upload(filePath, (res) = {          that.setData({            imageObject:res,            'userheadimg': res.imageURL,          })        }, (error) = {          console.error('error: ' + JSON.stringify(error));        },null, (progress) = {          console.log('上传进度', progress.progress)          console.log('已经上传的数据长度', progress.totalBytesSent)          console.log('预期需要上传的数据总长度', progress.totalBytesExpectedToSend)        }, cancelTask = that.setData({ cancelTask })        );      }    })  }

相关文档:

https://github.com/gpake/qiniu-wxapp-sdk/blob/master/README.md

版权声明

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

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

热门模板

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