uniapp七牛云上传图片or视频

// 上传视频
videoUpload() {
	var _this = this;
	var timestamp = Date.parse(new Date());
	var date = new Date(timestamp);
	// console.log("==现在时间==")
	// console.log(date)
	var Y = date.getFullYear(); //年
	var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1); //月
	var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(); //日
	var h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours(); //时
	var m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes(); //分
	var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds(); //秒
	// console.log(Y, M, D, h, m, s);

	uni.chooseVideo({
		sourceType: ['camera', 'album'],
		success: function(res) {
			console.log(res);
			var tempFilePath = res.tempFilePath;
			var tempName = tempFilePath.slice(11, 23);
			// console.log(tempName);

			var tempFormat = tempFilePath.substring(tempFilePath.lastIndexOf(".") + 1);
			// console.log(tempFormat);

			// 参数格式:2022_03_10_uni/2022-03-10_11:23:42_ab9.mp4
			var filePath = Y + '_' + M + '_' + D + '_uni/' + Y + '-' + M + '-' + D + '_' + h + ':' + m + ':' + s + '_' + tempName + '.' + tempFormat;
			console.log(filePath)

			// 普通上传
			uni.uploadFile({
				url: 'https://up-z2.qiniup.com', //华南区
				filePath: tempFilePath,
				name: 'file',
				formData: {
					'key': filePath,
					'token': _this.qiniuConfig.uptoken, //后台返回七牛云上传token
				},
				success: (res) => {
					console.log('==上传结果==')
					// console.log(res);
					if (res.statusCode == 200) {
						let result = JSON.parse(res.data);
						console.log(result)
						_this.videoSrc = _this.qiniuConfig.domain + '/' + result.key;
					} else {
						uni.showToast({
							title: '上传失败',
							icon: 'none',
							duration: 2000
						});
					}
				}
			});

		}
	});
},

七牛云文件上传接口,文件向匹配的接口中传输,存储区域对应 HTTPS 地址。

存储区域

区域代码HTTPS地址
华东ECNhttps://up.qiniup.com
华北NCNhttps://up-z1.qiniup.com
华南SCNhttps://up-z2.qiniup.com
北美NAhttps://up-na0.qiniup.com
新加坡ASGhttps://up-as0.qiniup.com

获取七牛云token示例

参考文献:基于七牛云 API 开发的微信小程序 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

 康 

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值