uploadToOss () {
let client = oss(this.ossConfig)
const data = this.file // 文件
const _this = this
let filename = data.name // 获取文件名
let suffix = filename.substring(data.name.lastIndexOf('.')) // 获取文件后缀
if (suffix !== '.mp4' && suffix !== '.3gp' && suffix !== '.ts' && suffix !== '.mkv') {
this.$message.error('视频格式不符合')
this.$refs.uploadVideo.clearFiles()
return
}
async function putObject () {
try {
// 在oss里创建文件夹
const result = await client.put('lrjk/testVideoGene/' + filename, data)
console.log(result)
let dataObj = {}
let realUrl = result.url.replace('http://coach-1.oss-cn-shanghai.aliyuncs.com', 'https://img.jx885.com')
dataObj.ossVideoUrl = realUrl
dataObj.name = data.name
_this.tableData.push(dataObj) //动态添加table数据
_this.$message.success('上传完毕')
_this.upVideoSize() //获取上传数量方法
} catch (e) {
this.$message.error('上传出错,请刷新重试')
console.log(e)
}
}
putObject()
},
结果为:
result:
Object
name: "lrjk/testVideoGene/ffvv123.mp4"
res: {status: 200, statusCode: 200, headers: {…}, size: 0, aborted: false, …}
url: "http://coach-1.oss-cn-shanghai.aliyuncs.com/lrxx/testdexxideoGenex/ffvv123.mp4"
[[Prototype]]: Object