小程序上传又拍云

34 篇文章 0 订阅
1 篇文章 0 订阅

官方文档参考https://help.upyun.com/knowledge-base/small_program/

小程序上传图片到又拍云不同于h5上传可以用input action="http://v0.api.upyun.com/miandan"方法

小程序注意要素

1、注意小程序配置安全域名

2、注意以下参数的配置,一定要正确

const upyun = new Upyun({ 

  bucket: '服务名称',

  operator: '操作员',

  getSignatureUrl: '获取signature的接口地址'

})

demo

3、注意文件保存路径问题remotePath的值可自定义,不需在又拍云后台配置文件夹

注意文件保存路径格式 '/ypy/image' + year + month + day + hour + minutes + second + millisecond + rnd + '.png' 

'/ypy/image' 为可自定义,时间戳为图片名称设置 、格式为png、

chooseImage: function () {

console.log('chooseImage')

const self = this

 

wx.chooseImage({

count: 1,

sizeType: ['compressed'],

sourceType: ['album'],

success: function (res) {

console.log('chooseImage success, temp path is', res.tempFilePaths[0])

 

const imageSrc = res.tempFilePaths[0]

var myDate = new Date();

var year = myDate.getFullYear();

var month = myDate.getMonth()+1;

var day = myDate.getDate();

var hour = myDate.getHours();

var minutes = myDate.getMinutes();

var second = myDate.getSeconds();

var millisecond = myDate.getMilliseconds();

var rnd = Math.floor(Math.random()*100000);

upyun.upload({

localPath: imageSrc,

remotePath: '/ypy/image' + year + month + day + hour + minutes + second + millisecond + rnd + '.png' ,

success: function (res) {

console.log('uploadImage success, res is:', res)

wx.showToast({

title: '上传成功',

icon: 'success',

duration: 1000

})

 

self.setData({

imageSrc

})

},

fail: function ({errMsg}) {

console.log('uploadImage fail, errMsg is', errMsg)

}

})

},

fail: function ({errMsg}) {

console.log('chooseImage fail, err is', errMsg)

}

})

}

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值