oss add upload file
This commit is contained in:
parent
4ca91dadca
commit
33becf6dca
@ -65,7 +65,6 @@
|
|||||||
"@vue/cli-plugin-unit-jest": "3.6.3",
|
"@vue/cli-plugin-unit-jest": "3.6.3",
|
||||||
"@vue/cli-service": "3.6.0",
|
"@vue/cli-service": "3.6.0",
|
||||||
"@vue/test-utils": "1.0.0-beta.29",
|
"@vue/test-utils": "1.0.0-beta.29",
|
||||||
"ali-oss": "^6.17.1",
|
|
||||||
"autoprefixer": "^9.5.1",
|
"autoprefixer": "^9.5.1",
|
||||||
"babel-core": "7.0.0-bridge.0",
|
"babel-core": "7.0.0-bridge.0",
|
||||||
"babel-eslint": "10.0.1",
|
"babel-eslint": "10.0.1",
|
||||||
|
|||||||
4
public/resource/aliyun-oss-sdk-6.17.0.min.js
vendored
4
public/resource/aliyun-oss-sdk-6.17.0.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,12 +0,0 @@
|
|||||||
import request from '@/utils/request'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
// 获取分享者信息
|
|
||||||
getAppToken: function(params) {
|
|
||||||
return request({
|
|
||||||
url: 'oss/aliyun/getAppToken',
|
|
||||||
method: 'get',
|
|
||||||
params
|
|
||||||
})
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@ -1011,8 +1011,16 @@ export default {
|
|||||||
if (!this.path) {
|
if (!this.path) {
|
||||||
this.path = ''
|
this.path = ''
|
||||||
}
|
}
|
||||||
if (this.path + '/' === fileDoc.$set.path) {
|
if (fileDoc) {
|
||||||
this.getFileList()
|
if (fileDoc.$set) {
|
||||||
|
if (this.path + '/' === fileDoc.$set.path) {
|
||||||
|
this.getFileList()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (this.path + '/' === fileDoc.path) {
|
||||||
|
this.getFileList()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -99,7 +99,7 @@ export default {
|
|||||||
username: this.$store.state.user.name,
|
username: this.$store.state.user.name,
|
||||||
options: {
|
options: {
|
||||||
target: api.simpleUploadURL,
|
target: api.simpleUploadURL,
|
||||||
chunkSize: 2 * 1024 * 1024,
|
chunkSize: 3 * 1024 * 1024,
|
||||||
// speedSmoothingFactor: 0.1,
|
// speedSmoothingFactor: 0.1,
|
||||||
// progressCallbacksInterval: 500,
|
// progressCallbacksInterval: 500,
|
||||||
maxChunkRetries: 3, // 最大重试次数
|
maxChunkRetries: 3, // 最大重试次数
|
||||||
|
|||||||
@ -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>
|
|
||||||
Loading…
x
Reference in New Issue
Block a user