Commit 26fa0202 authored by liujiangnan's avatar liujiangnan

feat

parent 39b2e852
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
:before-upload="beforeUpload" :before-upload="beforeUpload"
:on-change="handleFileChange" :on-change="handleFileChange"
:on-error="handleUploadError" :on-error="handleUploadError"
accept="video/*"> accept=".mp4,video/mp4,application/mp4">
<el-button type="primary" :loading="uploading" :disabled="uploading">选择视频</el-button> <el-button type="primary" :loading="uploading" :disabled="uploading">选择视频</el-button>
<span class="hint">支持重复上传,会覆盖当前视频</span> <span class="hint">支持重复上传,会覆盖当前视频</span>
</el-upload> </el-upload>
......
...@@ -82,13 +82,27 @@ new Vue({ ...@@ -82,13 +82,27 @@ new Vue({
} }
}, },
methods: { methods: {
/** 仅允许 .mp4;MIME 有值时须为 video/mp4 或 application/mp4(部分环境 type 为空则只靠扩展名) */
isMp4File: function (file) {
var raw = file && file.raw ? file.raw : file;
if (!raw || !raw.name) {
return false;
}
if (!/\.mp4$/i.test(raw.name)) {
return false;
}
var t = (raw.type || '').toLowerCase();
if (t && t !== 'video/mp4' && t !== 'application/mp4') {
return false;
}
return true;
},
beforeUpload: function (file) { beforeUpload: function (file) {
if (this.uploading) { if (this.uploading) {
this.$message.warning('正在上传,请稍候再试'); this.$message.warning('正在上传,请稍候再试');
return false; return false;
} }
var isMP4 = file.type === 'video/mp4'; if (!this.isMp4File(file)) {
if (!isMP4) {
this.$message.error('只能上传 mp4 文件'); this.$message.error('只能上传 mp4 文件');
return false; return false;
} }
...@@ -105,6 +119,9 @@ new Vue({ ...@@ -105,6 +119,9 @@ new Vue({
if (!rawFile) { if (!rawFile) {
return; return;
} }
if (!this.isMp4File(file)) {
return;
}
if (this.videoPreviewUrl && this.videoPreviewUrl.indexOf('blob:') === 0) { if (this.videoPreviewUrl && this.videoPreviewUrl.indexOf('blob:') === 0) {
URL.revokeObjectURL(this.videoPreviewUrl); URL.revokeObjectURL(this.videoPreviewUrl);
} }
...@@ -243,7 +260,7 @@ new Vue({ ...@@ -243,7 +260,7 @@ new Vue({
accessKeyId: ossConfig.accessKeyId, accessKeyId: ossConfig.accessKeyId,
accessKeySecret: ossConfig.accessKeySecret, accessKeySecret: ossConfig.accessKeySecret,
stsToken: ossConfig.securityToken, stsToken: ossConfig.securityToken,
bucket: 'iplayabc-worker-queue-video-mini', bucket: 'iplayabc-worker-queue-videolmh',
cors: true, cors: true,
secure: true, secure: true,
silent: true silent: true
...@@ -267,15 +284,14 @@ new Vue({ ...@@ -267,15 +284,14 @@ new Vue({
if (ext !== 'mp4') { if (ext !== 'mp4') {
return newFileName; return newFileName;
} }
var miniName = md5 + '_mini.mp4'; return videoClient.multipartUpload(newFileName, file, {
return videoClient.multipartUpload(miniName, file, {
progress: function (p) { progress: function (p) {
if (uploadId === _this.currentUploadId) { if (uploadId === _this.currentUploadId) {
_this.uploadProgress = Math.floor(p * 50) + 50; _this.uploadProgress = Math.floor(p * 50) + 50;
} }
} }
}).then(function () { }).then(function () {
return miniName; return newFileName;
}); });
}); });
}).then(function (fileName) { }).then(function (fileName) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment