<
html
>
<
head
>
<
script
src
=
"./lib/es6-promise.min.js"
>
<
/
script
>
<
script
src
=
"./lib/aliyun-oss-sdk-5.3.1.min.js"
>
<
/
script
>
<
script
src
=
"aliyun-upload-sdk-1.5.0.min.js"
>
<
/
script
>
</
head
>
<
body
>
<
form
action
=
""
>
<
input
type
=
"file"
name
=
"file"
id
=
"files"
accept
=
"video/mp4,video/mov"
multiple
=
""
/>
</
form
>
<
script
>
var
uploader
=
new
AliyunUpload
.
Vod
({
//阿里账号ID,必须有值 ,值的来源https://help.aliyun.com/knowledge_detail/37196.html
userId:
"1720442442383302"
,
//上传到点播的地域, 默认值为'cn-shanghai',//eu-central-1,ap-southeast-1
region:
"cn-shanghai"
,
//分片大小默认1M,不能小于100K
partSize:
1048576
,
//并行上传分片个数,默认5
parallel:
5
,
//网络原因失败时,重新上传次数,默认为3
retryCount:
3
,
//网络原因失败时,重新上传间隔时间,默认为2秒
retryDuration:
2
,
// 开始上传
'onUploadstarted'
:
function
(
uploadInfo
) {
console
.
log
(
"onUploadStarted:"
+
uploadInfo
.
file
.
name
+
", endpoint:"
+
uploadInfo
.
endpoint
+
", bucket:"
+
uploadInfo
.
bucket
+
", object:"
+
uploadInfo
.
object
);
//获取STS Token,设置到SDK
uploader
.
setSTSToken
(
uploadInfo
,
accessKeyId
,
accessKeySecret
,
secretToken
);
},
// 文件上传成功
'onUploadSucceed'
:
function
(
uploadInfo
) {
console
.
log
(
"onUploadSucceed: "
+
uploadInfo
.
file
.
name
+
", endpoint:"
+
uploadInfo
.
endpoint
+
", bucket:"
+
uploadInfo
.
bucket
+
", object:"
+
uploadInfo
.
object
);
},
// 文件上传失败
'onUploadFailed'
:
function
(
uploadInfo
,
code
,
message
) {
console
.
log
(
"onUploadFailed: file:"
+
uploadInfo
.
file
.
name
+
",code:"
+
code
+
", message:"
+
message
);
},
// 文件上传进度,单位:字节
'onUploadProgress'
:
function
(
uploadInfo
,
totalSize
,
loadedPercent
) {
console
.
log
(
"onUploadProgress:file:"
+
uploadInfo
.
file
.
name
+
", fileSize:"
+
totalSize
+
", percent:"
+
Math
.
ceil
(
loadedPercent
*
100
) +
"%"
);
},
// 上传凭证超时
'onUploadTokenExpired'
:
function
(
uploadInfo
) {
console
.
log
(
"onUploadTokenExpired"
);
//重新获取STS token,恢复上传
uploader
.
resumeUploadWithSTSToken
(
accessKeyId
,
accessKeySecret
,
secretToken
);
},
//全部文件上传结束
'onUploadEnd'
:
function
(
uploadInfo
) {
console
.
log
(
"onUploadEnd: uploaded all the files"
);
}
});
var
userData
= {
"Vod"
:
{
"Title"
:
"test"
,
"CateId"
:
"234"
}
};
document
.
getElementById
(
"files"
).
addEventListener
(
'change'
,
function
(
event
) {
for
(
var
i
=
0
;
i
<
event
.
target
.
files
.
length
;
i
++) {
// 逻辑代码
uploader
.
addFile
(
event
.
target
.
files
[
i
],
null
,
null
,
null
,
userData
);
}
uploader
.
startUpload
();
});
<
/
script
>
</
body
>
</
html
>