Skip to content

Commit

Permalink
分片上传支持 x-cos-meta 传递给 complete 接口
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Dec 1, 2020
1 parent e38e060 commit 893dde3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
17 changes: 14 additions & 3 deletions dist/cos-js-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -2161,7 +2161,7 @@ base.init(COS, task);
advance.init(COS, task);

COS.getAuthorization = util.getAuth;
COS.version = '1.1.1';
COS.version = '1.1.2';

module.exports = COS;

Expand Down Expand Up @@ -8362,12 +8362,17 @@ function sliceUploadFile(params, callback) {

// 上传分块完成,开始 uploadSliceComplete 操作
ep.on('upload_slice_complete', function (UploadData) {
var metaHeaders = {};
util.each(params.Headers, function (val, k) {
if (k.toLowerCase().indexOf('x-cos-meta-') === 0) metaHeaders[k] = val;
});
uploadSliceComplete.call(self, {
Bucket: Bucket,
Region: Region,
Key: Key,
UploadId: UploadData.UploadId,
SliceList: UploadData.SliceList
SliceList: UploadData.SliceList,
Headers: metaHeaders
}, function (err, data) {
if (!self._isRunningTask(TaskId)) return;
session.removeUsing(UploadData.UploadId);
Expand Down Expand Up @@ -8955,6 +8960,7 @@ function uploadSliceComplete(params, callback) {
var SliceList = params.SliceList;
var self = this;
var ChunkRetryTimes = this.options.ChunkRetryTimes + 1;
var Headers = params.Headers;
var Parts = SliceList.map(function (item) {
return {
PartNumber: item.PartNumber,
Expand All @@ -8968,7 +8974,8 @@ function uploadSliceComplete(params, callback) {
Region: Region,
Key: Key,
UploadId: UploadId,
Parts: Parts
Parts: Parts,
Headers: Headers
}, tryCallback);
}, function (err, data) {
callback(err, data);
Expand Down Expand Up @@ -9233,6 +9240,10 @@ function sliceCopyFile(params, callback) {

// 分片复制完成,开始 multipartComplete 操作
ep.on('copy_slice_complete', function (UploadData) {
var metaHeaders = {};
util.each(params.Headers, function (val, k) {
if (k.toLowerCase().indexOf('x-cos-meta-') === 0) metaHeaders[k] = val;
});
self.multipartComplete({
Bucket: Bucket,
Region: Region,
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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cos-js-sdk-v5",
"version": "1.1.1",
"version": "1.1.2",
"description": "JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)",
"main": "index.js",
"scripts": {
Expand Down
14 changes: 12 additions & 2 deletions src/advance.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ function sliceUploadFile(params, callback) {

// 上传分块完成,开始 uploadSliceComplete 操作
ep.on('upload_slice_complete', function (UploadData) {
var metaHeaders = {};
util.each(params.Headers, function (val, k) {
if (k.toLowerCase().indexOf('x-cos-meta-') === 0) metaHeaders[k] = val;
});
uploadSliceComplete.call(self, {
Bucket: Bucket,
Region: Region,
Key: Key,
UploadId: UploadData.UploadId,
SliceList: UploadData.SliceList,
Headers: metaHeaders,
}, function (err, data) {
if (!self._isRunningTask(TaskId)) return;
session.removeUsing(UploadData.UploadId);
Expand Down Expand Up @@ -627,6 +632,7 @@ function uploadSliceComplete(params, callback) {
var SliceList = params.SliceList;
var self = this;
var ChunkRetryTimes = this.options.ChunkRetryTimes + 1;
var Headers = params.Headers;
var Parts = SliceList.map(function (item) {
return {
PartNumber: item.PartNumber,
Expand All @@ -640,7 +646,8 @@ function uploadSliceComplete(params, callback) {
Region: Region,
Key: Key,
UploadId: UploadId,
Parts: Parts
Parts: Parts,
Headers: Headers,
}, tryCallback);
}, function (err, data) {
callback(err, data);
Expand Down Expand Up @@ -905,7 +912,10 @@ function sliceCopyFile(params, callback) {
var onProgress;

// 分片复制完成,开始 multipartComplete 操作
ep.on('copy_slice_complete', function (UploadData) {
ep.on('copy_slice_complete', function (UploadData) {var metaHeaders = {};
util.each(params.Headers, function (val, k) {
if (k.toLowerCase().indexOf('x-cos-meta-') === 0) metaHeaders[k] = val;
});
self.multipartComplete({
Bucket: Bucket,
Region: Region,
Expand Down
2 changes: 1 addition & 1 deletion src/cos.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ base.init(COS, task);
advance.init(COS, task);

COS.getAuthorization = util.getAuth;
COS.version = '1.1.1';
COS.version = '1.1.2';

module.exports = COS;

0 comments on commit 893dde3

Please sign in to comment.