Skip to content

Commit 2f09a2a

Browse files
committed
add accept attribute for profile to filter files.
1 parent fd41240 commit 2f09a2a

5 files changed

+9
-5
lines changed

dist/qiniu-uploader.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var Profile = function Profile(uploader) {
1818
this.bucket = options.bucket;
1919
this.domain = options.domain;
2020
this.ssl = options.ssl || false;
21+
this.accept = options.accept;
2122
this.uptokenUrl = options.uptokenUrl;
2223

2324
this["public"] = true;
@@ -80,6 +81,7 @@ var QiniuUploader = (function () {
8081
var uploader = this;
8182
var input = document.createElement('input');
8283
input.setAttribute('type', 'file');
84+
input.setAttribute('accept', profile.accept);
8385

8486
Object.assign(input.style, {
8587
visibility: 'hidden',
@@ -90,7 +92,7 @@ var QiniuUploader = (function () {
9092

9193
document.body.appendChild(input);
9294
input.addEventListener('change', function (e) {
93-
if (e.target.value) {
95+
if (input.value.length > 0) {
9496
uploader.addFiles(e.target.files, element, profile);
9597
}
9698

dist/qiniu-uploader.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/qiniu-uploader.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/profile.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default class Profile {
66
this.bucket = options.bucket;
77
this.domain = options.domain;
88
this.ssl = options.ssl || false;
9+
this.accept = options.accept;
910
this.uptokenUrl = options.uptokenUrl;
1011

1112
this.public = true;

src/qiniu-uploader.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class QiniuUploader {
4343
var uploader = this;
4444
var input = document.createElement('input');
4545
input.setAttribute('type', 'file');
46+
input.setAttribute('accept', profile.accept);
4647

4748
Object.assign(input.style, {
4849
visibility: 'hidden',
@@ -53,7 +54,7 @@ class QiniuUploader {
5354

5455
document.body.appendChild(input);
5556
input.addEventListener('change', e => {
56-
if (e.target.value) {
57+
if (input.value.length > 0) {
5758
uploader.addFiles(e.target.files, element, profile);
5859
}
5960

0 commit comments

Comments
 (0)