fix: upload assets through backend
This commit is contained in:
parent
70c5e362c9
commit
b6d5c1c0f2
@ -10,12 +10,11 @@ VUE_APP_BASE_URL ='https://console.atuchat.com'
|
||||
# VUE_APP_BASE_URL = 'https://console.azizichat.com'
|
||||
|
||||
# oss
|
||||
VUE_APP_OSS_BUCKET = 'tkm-likei'
|
||||
VUE_APP_OSS_URL = 'https://tkm-likei.oss-ap-southeast-1.aliyuncs.com'
|
||||
VUE_APP_OSS_BUCKET = 'asset-global-interaction-1420526837'
|
||||
VUE_APP_OSS_URL = 'https://asset.global-interaction.com'
|
||||
|
||||
# h5
|
||||
VUE_APP_H5_BASE_URL = 'https://h5.azizichat.com'
|
||||
|
||||
# start mock
|
||||
VUE_APP_START_MOCK = false
|
||||
|
||||
|
||||
@ -10,8 +10,8 @@ VUE_CLI_BABEL_TRANSPILE_MODULES = true
|
||||
VUE_APP_BASE_URL ='https://console.atuchat.com'
|
||||
|
||||
# oss
|
||||
VUE_APP_OSS_BUCKET = 'tkm-likei'
|
||||
VUE_APP_OSS_URL = 'https://tkm-likei.oss-ap-southeast-1.aliyuncs.com'
|
||||
VUE_APP_OSS_BUCKET = 'asset-global-interaction-1420526837'
|
||||
VUE_APP_OSS_URL = 'https://asset.global-interaction.com'
|
||||
|
||||
# h5
|
||||
VUE_APP_H5_BASE_URL = 'https://h5.azizichat.com'
|
||||
|
||||
@ -8,8 +8,8 @@ VUE_APP_BASE_API = '/console'
|
||||
VUE_APP_BASE_URL = 'https://console.azizichat.com'
|
||||
|
||||
# oss
|
||||
VUE_APP_OSS_BUCKET = 'tkm-likei'
|
||||
VUE_APP_OSS_URL = 'https://tkm-likei.oss-ap-southeast-1.aliyuncs.com'
|
||||
VUE_APP_OSS_BUCKET = 'asset-global-interaction-1420526837'
|
||||
VUE_APP_OSS_URL = 'https://asset.global-interaction.com'
|
||||
|
||||
# h5
|
||||
VUE_APP_H5_BASE_URL = 'https://h5.azizichat.com'
|
||||
|
||||
@ -9,8 +9,8 @@ VUE_APP_BASE_API = '/console'
|
||||
VUE_APP_BASE_URL = 'https://console.azizichat.com'
|
||||
|
||||
# oss
|
||||
VUE_APP_OSS_BUCKET = 'tkm-likei'
|
||||
VUE_APP_OSS_URL = 'https://tkm-likei.oss-ap-southeast-1.aliyuncs.com'
|
||||
VUE_APP_OSS_BUCKET = 'asset-global-interaction-1420526837'
|
||||
VUE_APP_OSS_URL = 'https://asset.global-interaction.com'
|
||||
|
||||
# h5
|
||||
VUE_APP_H5_BASE_URL = 'https://h5.azizichat.com'
|
||||
|
||||
@ -16,7 +16,7 @@ export default [
|
||||
'updateUser': '23',
|
||||
'id': '1354012611532255233',
|
||||
'link': 'ddd',
|
||||
'cover': 'http://sugartime-dev.oss-accelerate.aliyuncs.com/manager-e22186b3-e630-4451-8816-daeecf6377b2.jpg',
|
||||
'cover': 'https://asset.global-interaction.com/mock/manager-e22186b3-e630-4451-8816-daeecf6377b2.jpg',
|
||||
'showcase': true,
|
||||
'expiredTime': '2021-01-11 02:03:02',
|
||||
'depict': 'dee'
|
||||
|
||||
@ -17,7 +17,7 @@ export default [
|
||||
'userId': '1351021829418778626',
|
||||
'propsId': '1351727566616408065',
|
||||
'propsCandy': 50.00,
|
||||
'propsPhoto': 'http://sugartime-dev.oss-accelerate.aliyuncs.com/manager-80db3c54-4164-4f9b-a1d3-28ae96525c64.jpg',
|
||||
'propsPhoto': 'https://asset.global-interaction.com/mock/manager-80db3c54-4164-4f9b-a1d3-28ae96525c64.jpg',
|
||||
'propsName': 'yy',
|
||||
'typeName': '头像框',
|
||||
'userBaseInfo': {
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@lucky-canvas/vue": "0.0.5",
|
||||
"ali-oss": "^6.12.0",
|
||||
"axios": "0.18.1",
|
||||
"codemirror": "5.45.0",
|
||||
"current-device": "0.10.2",
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
|
||||
import OSS from 'ali-oss'
|
||||
import request from '@/utils/request'
|
||||
import { uuid } from '@/utils'
|
||||
|
||||
@ -18,6 +16,9 @@ const getAccessImgUrl = (key) => {
|
||||
if (!key) {
|
||||
return ''
|
||||
}
|
||||
if (/^https?:\/\//i.test(key)) {
|
||||
return key
|
||||
}
|
||||
if (key.startsWith('/')) {
|
||||
return `${process.env.VUE_APP_OSS_URL}${key}`
|
||||
}
|
||||
@ -30,32 +31,22 @@ const getAccessImgUrl = (key) => {
|
||||
*/
|
||||
const simpleUploadFlie = (fileObj, dir) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const filename = fileObj.customFilename || radmonFilename(fileObj.file.name)
|
||||
const key = `${dir || 'other'}/${filename}`
|
||||
const formData = new FormData()
|
||||
formData.append('file', fileObj.file)
|
||||
formData.append('key', key)
|
||||
request({
|
||||
url: '/ali-yun/oss/sts',
|
||||
method: 'get'
|
||||
url: '/ali-yun/oss/upload',
|
||||
method: 'post',
|
||||
data: formData
|
||||
}).then(res => {
|
||||
const stsResult = res.body
|
||||
if (stsResult) {
|
||||
const client = new OSS({
|
||||
endpoint: 'oss-accelerate.aliyuncs.com',
|
||||
accessKeyId: stsResult['AccessKeyId'],
|
||||
accessKeySecret: stsResult['AccessKeySecret'],
|
||||
stsToken: stsResult['SecurityToken'],
|
||||
bucket: process.env.VUE_APP_OSS_BUCKET
|
||||
})
|
||||
try {
|
||||
const filename = fileObj.customFilename || radmonFilename(fileObj.file.name)
|
||||
client.put(`${dir || 'other'}/${filename}`, fileObj.file).then(ossRes => {
|
||||
resolve(ossRes)
|
||||
}).catch(er => {
|
||||
console.error('error:', er)
|
||||
reject(er)
|
||||
})
|
||||
} catch (er) {
|
||||
console.error('error:', er)
|
||||
reject(er)
|
||||
}
|
||||
}
|
||||
const body = res.body || {}
|
||||
resolve({
|
||||
name: body.name || key,
|
||||
url: body.url || getAccessImgUrl(body.name || key),
|
||||
res: body.res || { status: 200 }
|
||||
})
|
||||
}).catch(er => {
|
||||
console.error(er)
|
||||
reject(er)
|
||||
|
||||
4
项目说明.md
4
项目说明.md
@ -28,7 +28,7 @@
|
||||
| **国际化** | 自研 i18n 插件(基于时区自动检测语言) |
|
||||
| **样式** | SCSS + normalize.css,支持暗色主题切换 |
|
||||
| **富媒体** | Video.js 8、SVGA Player、libpag(PAG 动效) |
|
||||
| **文件存储** | 阿里云 OSS(ali-oss SDK) |
|
||||
| **文件存储** | 腾讯云 COS(通过后端接口上传) |
|
||||
| **WebSocket** | SockJS + StompJS(实时消息) |
|
||||
| **Mock** | Mock.js(开发环境可选启用) |
|
||||
| **代码规范** | ESLint(babel-eslint)+ EditorConfig |
|
||||
@ -222,7 +222,7 @@ meta: {
|
||||
|
||||
## 十、OSS 文件上传
|
||||
|
||||
阿里云 OSS,Bucket 分类:
|
||||
腾讯云 COS,目录分类:
|
||||
|
||||
| Bucket Key | 用途 |
|
||||
|------------|------|
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user