增加上传文件取消提示

This commit is contained in:
2024-09-06 13:37:14 +08:00
parent 10ae05ce75
commit e6d421dfb1
4 changed files with 45 additions and 17 deletions

View File

@@ -10,6 +10,8 @@ const $config = {
accessKeySecret: "",
bucket: "cashier-oss"
}
import { Notification } from 'element-ui'
async function uploadAndDownloadFile(name, file, headers) {
return new Promise((resolve, reject) => {
try {
@@ -39,16 +41,16 @@ class ossClient {
refreshSTSTokenInterval: 3600 * 1000
});
}
async upload(name, file, progressCallback) {
async upload(name, file, progressCallback) {
try {
let options = {
// 获取分片上传进度、断点和返回值。
progress: progressCallback,
headers:$headers
headers: $headers
}
const {
res: resp
} = await this.ossClient.put(name, file,options).catch(error => {
} = await this.ossClient.put(name, file, options).catch(error => {
reject(error);
})
return resp.requestUrls
@@ -81,10 +83,21 @@ class ossClient {
res: resp
} = await this.ossClient.multipartUpload(name ? name : file.name, file, options)
// return resp.requestUrls
console.log('------resp---');
console.log(resp)
return `${resp.requestUrls[0]}`.split('?')[0]
} catch (e) {
console.log('------e---');
console.log(e);
if (e.name == 'cancel') {
Notification.error({
title: '上传已取消',
duration: 3000
})
return e
}
}
}
@@ -94,8 +107,15 @@ class ossClient {
* @param {Object} uploadId
* @param {Object} name
*/
abortUpload(uploadId, name) {
this.client.abortMultipartUpload(name, uploadId)
async abortUpload(uploadId, name) {
try {
const res=await this.ossClient.abortMultipartUpload(name, uploadId)
return res
} catch (error) {
console.log(error)
return error
}
}