oss add upload file

This commit is contained in:
jmal 2023-04-08 19:56:41 +08:00
parent 4ca91dadca
commit 33becf6dca
6 changed files with 11 additions and 85 deletions

View File

@ -65,7 +65,6 @@
"@vue/cli-plugin-unit-jest": "3.6.3",
"@vue/cli-service": "3.6.0",
"@vue/test-utils": "1.0.0-beta.29",
"ali-oss": "^6.17.1",
"autoprefixer": "^9.5.1",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.0.1",

File diff suppressed because one or more lines are too long

View File

@ -1,12 +0,0 @@
import request from '@/utils/request'
export default {
// 获取分享者信息
getAppToken: function(params) {
return request({
url: 'oss/aliyun/getAppToken',
method: 'get',
params
})
},
}

View File

@ -1011,8 +1011,16 @@ export default {
if (!this.path) {
this.path = ''
}
if (this.path + '/' === fileDoc.$set.path) {
this.getFileList()
if (fileDoc) {
if (fileDoc.$set) {
if (this.path + '/' === fileDoc.$set.path) {
this.getFileList()
}
} else {
if (this.path + '/' === fileDoc.path) {
this.getFileList()
}
}
}
}
},

View File

@ -99,7 +99,7 @@ export default {
username: this.$store.state.user.name,
options: {
target: api.simpleUploadURL,
chunkSize: 2 * 1024 * 1024,
chunkSize: 3 * 1024 * 1024,
// speedSmoothingFactor: 0.1,
// progressCallbacksInterval: 500,
maxChunkRetries: 3, // 最大重试次数

View File

@ -1,65 +0,0 @@
<template>
<input type="file" id="file" />
</template>
<script>
import OSS from "ali-oss"
import aliyunOSSApi from "@/api/aliyunoss";
export default {
name: "testoss",
data() {
return {
stsServerUrl: "http://localhost:7080/",
accessToken: {
AccessKeyId: '',
AccessKeySecret: '',
Expiration: '',
SecurityToken: ''
}
}
},
mounted() {
this.getAccessToken()
let that = this
document.getElementById('file').addEventListener('change', function (e) {
let file = e.target.files[0];
let storeAs = file.name;
console.log(file.name + ' => ' + storeAs);
let client = new OSS({
accessKeyId: that.accessToken.AccessKeyId,
accessKeySecret: that.accessToken.AccessKeySecret,
stsToken: that.accessToken.SecurityToken,
endpoint: 'oss-cn-guangzhou.aliyuncs.com',
bucket: 'jmalcloud',
internal: true,
cname: false,
secure: true,
refreshSTSToken: async () => this.refreshToken()
});
// storeAs可以自定义为文件名(例如file.txt)或目录(例如abc/test/file.txt)的形式,实现将文件上传至当前Bucket或Bucket下的指定目录。
// file可以自定义为File对象、Blob数据以及OSS Buffer。
client.multipartUpload(storeAs, file).then(function (result) {
console.log(result);
}).catch(function (err) {
console.log(err);
});
});
},
methods: {
getAccessToken() {
aliyunOSSApi.getAppToken().then((res) => {
this.accessToken = res.data
})
},
async refreshToken() {
this.getAccessToken()
}
}
}
</script>
<style scoped>
</style>