Skip to content

Commit

Permalink
上传支持 AddMetaMd5
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Aug 1, 2019
1 parent 811bc40 commit f4eeea4
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 45 deletions.
81 changes: 42 additions & 39 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,50 +745,53 @@ function sliceUploadFile() {
}

function selectFileToUpload() {
var input = document.createElement('input');
var input = document.getElementById('file_selector') || document.createElement('input');
input.type = 'file';
input.onchange = function (e) {
document.body.removeChild(input);
var file = this.files[0];
if (file) {
if (file.size > 1024 * 1024) {
cos.sliceUploadFile({
Bucket: config.Bucket, // Bucket 格式:test-1250000000
Region: config.Region,
Key: file.name,
Body: file,
onTaskReady: function (tid) {
TaskId = tid;
},
onHashProgress: function (progressData) {
logger.log('onHashProgress', JSON.stringify(progressData));
},
onProgress: function (progressData) {
logger.log('onProgress', JSON.stringify(progressData));
},
}, function (err, data) {
logger.log(err || data);
});
} else {
cos.putObject({
Bucket: config.Bucket, // Bucket 格式:test-1250000000
Region: config.Region,
Key: file.name,
Body: file,
onTaskReady: function (tid) {
TaskId = tid;
},
onHashProgress: function (progressData) {
logger.log('onHashProgress', JSON.stringify(progressData));
},
onProgress: function (progressData) {
logger.log(JSON.stringify(progressData));
},
}, function (err, data) {
logger.log(err || data);
});
}
if (!file) return;
if (file.size > 1024 * 1024) {
cos.sliceUploadFile({
Bucket: config.Bucket, // Bucket 格式:test-1250000000
Region: config.Region,
Key: file.name,
Body: file,
onTaskReady: function (tid) {
TaskId = tid;
},
onHashProgress: function (progressData) {
logger.log('onHashProgress', JSON.stringify(progressData));
},
onProgress: function (progressData) {
logger.log('onProgress', JSON.stringify(progressData));
},
}, function (err, data) {
logger.log(err || data);
});
} else {
cos.putObject({
Bucket: config.Bucket, // Bucket 格式:test-1250000000
Region: config.Region,
Key: file.name,
Body: file,
onTaskReady: function (tid) {
TaskId = tid;
},
onHashProgress: function (progressData) {
logger.log('onHashProgress', JSON.stringify(progressData));
},
onProgress: function (progressData) {
logger.log(JSON.stringify(progressData));
},
}, function (err, data) {
logger.log(err || data);
});
}
};
input.style = 'width:0;height:0;border:0;margin:0;padding:0;';
input.id = 'file_selector';
document.body.appendChild(input);
input.click();
}

Expand Down
1 change: 0 additions & 1 deletion demo/queue/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ new Vue({
created: function () {
var self = this;
cos.on('list-update', function (data) {
console.log('list-update');
self.list = data.list;
self.total = data.list.length;
});
Expand Down
4 changes: 2 additions & 2 deletions dist/cos-js-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ var readAsBinaryString = function (blob, callback) {
};

// 获取文件 md5 值
var md5ChunkSize = 1024 * 1024 * 100;
var md5ChunkSize = 1024 * 1024;
var getFileMd5 = function (blob, callback, onProgress) {
var size = blob.size;
var loaded = 0;
Expand Down Expand Up @@ -3976,7 +3976,7 @@ var initTask = function (cos) {
if (task && (task.state === 'paused' || task.state === 'error')) {
task.state = 'waiting';
options && emitListUpdate();
nextUploadIndex = Math.min(nextUploadIndex, task.index);
nextUploadIndex = 0;
startNextTask();
}
};
Expand Down
2 changes: 1 addition & 1 deletion dist/cos-js-sdk-v5.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ var initTask = function (cos) {
if (task && (task.state === 'paused' || task.state === 'error')) {
task.state = 'waiting';
options && emitListUpdate();
nextUploadIndex = Math.min(nextUploadIndex, task.index);
nextUploadIndex = 0;
startNextTask();
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ var readAsBinaryString = function (blob, callback) {
};

// 获取文件 md5 值
var md5ChunkSize = 1024 * 1024 * 100;
var md5ChunkSize = 1024 * 1024;
var getFileMd5 = function (blob, callback, onProgress) {
var size = blob.size;
var loaded = 0;
Expand Down

0 comments on commit f4eeea4

Please sign in to comment.