驾考受理查询支付宝小程序、网页
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

53 lines
1.3 KiB

import OSS from "ali-oss"
import { v4 as uuidv4 } from 'uuid';
function uploadFileToOSS(file) {
uni.showLoading({
title: '图片上传中...'
});
return new Promise((resolve,reject) => {
// 创建OSS实例
const client = new OSS({
// region: 'oss-cn-shenzhen',
// accessKeyId: 'LTAI5tMan18fjJPUtr3Aim2W',
// accessKeySecret: 'lhALqqgYijc115wY8c1KfTYkbSnq5I',
// bucket: 'mangoimageapplet',
// endpoint:'oss-cn-shenzhen.aliyuncs.com'
//桶的地址
region: 'oss-cn-guangzhou',
//id
accessKeyId:'LTAI5tNycA46YTwm383dRvMV',
//密钥
accessKeySecret:'tAdbYQCmdur6jbZ8hjvgB7T1Z52mIG',
//桶的名字
bucket: 'zhuoqiu-image',
endpoint:'oss-cn-guangzhou.aliyuncs.com',
});
// 设置文件名和文件目录
const suffix = '.' + file.name.split('.').pop();
const fileName = uuidv4() + suffix; // 注意:文件名需要是唯一的
// 使用put接口上传文件
client.multipartUpload(fileName, file, {
headers: {
'Content-Disposition': 'inline',
'Content-Type': file.type
}
}).then(res => {
uni.hideLoading();
resolve('https://tennis-oss.xzaiyp.top/' + res.name);
}).catch(err => {
uni.hideLoading();
reject(err)
})
})
}
export default uploadFileToOSS