uniapp integrates Qiniu Cloud and uploads pictures

1 Create a project I created the project visually, and the project created by cli can directly use npm to install Qiniu cloud.

insert image description here

2 Copy qiniuUploader.js to the project, and the following reply puts the Baidu cloud link of qiniuUploader.js.

insert image description here

3 Introduce in the vue file that needs to use qiniuUploader.

insert image description here
4 Select a photo in the album, or after taking a photo, use the upload code
insert image description here

                //this.avatarUrl相册选中的文件 路径 , 或者拍照过来的文件路径   
				qiniuUploader.upload(this.avatarUrl, (res) => {
    
    
					console.log('res: ' + res);
				}, (error) => {
    
    
					console.log('error: ' + error);
				}, {
    
    
					region: 'SCN', //服务器区域号 // ECN, SCN, NCN, NA, ASG,分别对应七牛的:华东,华南,华北,北美,新加坡 5 个区域
					domain: 'rxarlaoh7.hn-bkt.clouddn.com', //七牛云域名  在对象存储--域名里面有
					key: "ss-imgs.png", // 文件名称   这个名称是七牛云上的文件名称。可以和相册选择的文件名称不一样。
					uptoken: "WqPk4QRUte=", // 公司后台服务器接口请求 获取的。
				}, (res) => {
    
    
					console.log('上传进度', res.progress)
					console.log('已经上传的数据长度', res.totalBytesSent)
					console.log('预期需要上传的数据总长度', res
						.totalBytesExpectedToSend)
				}, (res) => {
    
    
					// 取消上传
				}, (res) => {
    
    
					// `before` 上传前执行的操作
				}, (err) => {
    
    
					// `complete` 上传接受后执行的操作(无论成功还是失败都执行)
				});

Guess you like

Origin blog.csdn.net/sun6223508/article/details/131740452