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