7
7
exports [ "COS" ] = factory ( ) ;
8
8
else
9
9
root [ "COS" ] = factory ( ) ;
10
- } ) ( this , function ( ) {
10
+ } ) ( typeof self !== 'undefined' ? self : this , function ( ) {
11
11
return /******/ ( function ( modules ) { // webpackBootstrap
12
12
/******/ // The module cache
13
13
/******/ var installedModules = { } ;
@@ -582,6 +582,22 @@ util.getFileUUID = function (file, ChunkSize) {
582
582
return null ;
583
583
}
584
584
} ;
585
+ util . getBodyMd5 = function ( UploadCheckContentMd5 , Body , callback ) {
586
+ callback = callback || noop ;
587
+ if ( UploadCheckContentMd5 ) {
588
+ if ( typeof Body === 'string' ) {
589
+ callback ( util . md5 ( Body , true ) ) ;
590
+ } else if ( Body instanceof global . Blob ) {
591
+ util . getFileMd5 ( Body , function ( err , md5 ) {
592
+ callback ( md5 ) ;
593
+ } ) ;
594
+ } else {
595
+ callback ( ) ;
596
+ }
597
+ } else {
598
+ callback ( ) ;
599
+ }
600
+ } ;
585
601
586
602
module . exports = util ;
587
603
/* WEBPACK VAR INJECTION */ } . call ( exports , __webpack_require__ ( 5 ) ) )
@@ -1909,12 +1925,14 @@ var defaultOptions = {
1909
1925
CopySliceSize : 1024 * 1024 * 10 ,
1910
1926
ProgressInterval : 1000 ,
1911
1927
UploadQueueSize : 10000 ,
1928
+ UploadIdCacheLimit : 50 ,
1929
+ UploadCheckContentMd5 : false ,
1912
1930
Domain : '' ,
1913
1931
ServiceDomain : '' ,
1914
1932
Protocol : '' ,
1915
1933
CompatibilityMode : false ,
1916
1934
ForcePathStyle : false ,
1917
- UploadIdCacheLimit : 50
1935
+ XCosSecurityToken : ''
1918
1936
} ;
1919
1937
1920
1938
// 对外暴露的类
@@ -1938,7 +1956,7 @@ util.extend(COS.prototype, base);
1938
1956
util . extend ( COS . prototype , advance ) ;
1939
1957
1940
1958
COS . getAuthorization = util . getAuth ;
1941
- COS . version = '0.4.21 ' ;
1959
+ COS . version = '0.4.22 ' ;
1942
1960
1943
1961
module . exports = COS ;
1944
1962
@@ -4825,39 +4843,42 @@ function putObject(params, callback) {
4825
4843
var FileSize = params . ContentLength ;
4826
4844
var onProgress = util . throttleOnProgress . call ( self , FileSize , params . onProgress ) ;
4827
4845
4828
- submitRequest . call ( self , {
4829
- TaskId : params . TaskId ,
4830
- method : 'PUT' ,
4831
- Bucket : params . Bucket ,
4832
- Region : params . Region ,
4833
- Key : params . Key ,
4834
- headers : params . Headers ,
4835
- body : params . Body ,
4836
- onProgress : onProgress
4837
- } , function ( err , data ) {
4838
- if ( err ) {
4839
- onProgress ( null , true ) ;
4840
- return callback ( err ) ;
4841
- }
4842
- onProgress ( { loaded : FileSize , total : FileSize } , true ) ;
4843
- if ( data && data . headers && data . headers [ 'etag' ] ) {
4844
- var url = getUrl ( {
4845
- ForcePathStyle : self . options . ForcePathStyle ,
4846
- protocol : self . options . Protocol ,
4847
- domain : self . options . Domain ,
4848
- bucket : params . Bucket ,
4849
- region : params . Region ,
4850
- object : params . Key
4851
- } ) ;
4852
- url = url . substr ( url . indexOf ( '://' ) + 3 ) ;
4853
- return callback ( null , {
4854
- Location : url ,
4855
- ETag : data . headers [ 'etag' ] ,
4856
- statusCode : data . statusCode ,
4857
- headers : data . headers
4858
- } ) ;
4859
- }
4860
- callback ( null , data ) ;
4846
+ util . getBodyMd5 ( self . options . UploadCheckContentMd5 , params . Body , function ( md5 ) {
4847
+ md5 && ( params . Headers [ 'Content-MD5' ] = util . binaryBase64 ( md5 ) ) ;
4848
+ submitRequest . call ( self , {
4849
+ TaskId : params . TaskId ,
4850
+ method : 'PUT' ,
4851
+ Bucket : params . Bucket ,
4852
+ Region : params . Region ,
4853
+ Key : params . Key ,
4854
+ headers : params . Headers ,
4855
+ body : params . Body ,
4856
+ onProgress : onProgress
4857
+ } , function ( err , data ) {
4858
+ if ( err ) {
4859
+ onProgress ( null , true ) ;
4860
+ return callback ( err ) ;
4861
+ }
4862
+ onProgress ( { loaded : FileSize , total : FileSize } , true ) ;
4863
+ if ( data && data . headers && data . headers [ 'etag' ] ) {
4864
+ var url = getUrl ( {
4865
+ ForcePathStyle : self . options . ForcePathStyle ,
4866
+ protocol : self . options . Protocol ,
4867
+ domain : self . options . Domain ,
4868
+ bucket : params . Bucket ,
4869
+ region : params . Region ,
4870
+ object : params . Key
4871
+ } ) ;
4872
+ url = url . substr ( url . indexOf ( '://' ) + 3 ) ;
4873
+ return callback ( null , {
4874
+ Location : url ,
4875
+ ETag : data . headers [ 'etag' ] ,
4876
+ statusCode : data . statusCode ,
4877
+ headers : data . headers
4878
+ } ) ;
4879
+ }
4880
+ callback ( null , data ) ;
4881
+ } ) ;
4861
4882
} ) ;
4862
4883
}
4863
4884
@@ -5246,28 +5267,31 @@ function multipartUpload(params, callback) {
5246
5267
5247
5268
var self = this ;
5248
5269
util . getFileSize ( 'multipartUpload' , params , function ( ) {
5249
- submitRequest . call ( self , {
5250
- TaskId : params . TaskId ,
5251
- method : 'PUT' ,
5252
- Bucket : params . Bucket ,
5253
- Region : params . Region ,
5254
- Key : params . Key ,
5255
- qs : {
5256
- partNumber : params [ 'PartNumber' ] ,
5257
- uploadId : params [ 'UploadId' ]
5258
- } ,
5259
- headers : params . Headers ,
5260
- onProgress : params . onProgress ,
5261
- body : params . Body || null
5262
- } , function ( err , data ) {
5263
- if ( err ) {
5264
- return callback ( err ) ;
5265
- }
5266
- data [ 'headers' ] = data [ 'headers' ] || { } ;
5267
- callback ( null , {
5268
- ETag : data [ 'headers' ] [ 'etag' ] || '' ,
5269
- statusCode : data . statusCode ,
5270
- headers : data . headers
5270
+ util . getBodyMd5 ( self . options . UploadCheckContentMd5 , params . Body , function ( md5 ) {
5271
+ md5 && ( params . Headers [ 'Content-MD5' ] = util . binaryBase64 ( md5 ) ) ;
5272
+ submitRequest . call ( self , {
5273
+ TaskId : params . TaskId ,
5274
+ method : 'PUT' ,
5275
+ Bucket : params . Bucket ,
5276
+ Region : params . Region ,
5277
+ Key : params . Key ,
5278
+ qs : {
5279
+ partNumber : params [ 'PartNumber' ] ,
5280
+ uploadId : params [ 'UploadId' ]
5281
+ } ,
5282
+ headers : params . Headers ,
5283
+ onProgress : params . onProgress ,
5284
+ body : params . Body || null
5285
+ } , function ( err , data ) {
5286
+ if ( err ) {
5287
+ return callback ( err ) ;
5288
+ }
5289
+ data [ 'headers' ] = data [ 'headers' ] || { } ;
5290
+ callback ( null , {
5291
+ ETag : data [ 'headers' ] [ 'etag' ] || '' ,
5292
+ statusCode : data . statusCode ,
5293
+ headers : data . headers
5294
+ } ) ;
5271
5295
} ) ;
5272
5296
} ) ;
5273
5297
} ) ;
@@ -5529,7 +5553,7 @@ function getObjectUrl(params, callback) {
5529
5553
callback ( null , { Url : url } ) ;
5530
5554
return url ;
5531
5555
}
5532
- var authorization = getAuthorizationAsync . call ( this , {
5556
+ var AuthData = getAuthorizationAsync . call ( this , {
5533
5557
Bucket : params . Bucket || '' ,
5534
5558
Region : params . Region || '' ,
5535
5559
Method : params . Method || 'get' ,
@@ -5538,7 +5562,7 @@ function getObjectUrl(params, callback) {
5538
5562
} , function ( AuthData ) {
5539
5563
if ( ! callback ) return ;
5540
5564
var signUrl = url ;
5541
- signUrl += '?sign= ' + encodeURIComponent ( AuthData . Authorization ) ;
5565
+ signUrl += '?' + AuthData . Authorization ;
5542
5566
AuthData . XCosSecurityToken && ( signUrl += '&x-cos-security-token=' + AuthData . XCosSecurityToken ) ;
5543
5567
AuthData . ClientIP && ( signUrl += '&clientIP=' + AuthData . ClientIP ) ;
5544
5568
AuthData . ClientUA && ( signUrl += '&clientUA=' + AuthData . ClientUA ) ;
@@ -5547,8 +5571,8 @@ function getObjectUrl(params, callback) {
5547
5571
callback ( null , { Url : signUrl } ) ;
5548
5572
} ) ;
5549
5573
} ) ;
5550
- if ( authorization ) {
5551
- return url + '?sign= ' + encodeURIComponent ( authorization ) ;
5574
+ if ( AuthData ) {
5575
+ return url + '?' + AuthData . Authorization + ( AuthData . XCosSecurityToken ? '&x-cos-security-token=' + AuthData . XCosSecurityToken : '' ) ;
5552
5576
} else {
5553
5577
return url ;
5554
5578
}
@@ -5730,17 +5754,23 @@ function getAuthorizationAsync(params, callback) {
5730
5754
} ) ;
5731
5755
} else {
5732
5756
// 内部计算获取签名
5733
- var Authorization = util . getAuth ( {
5734
- SecretId : params . SecretId || self . options . SecretId ,
5735
- SecretKey : params . SecretKey || self . options . SecretKey ,
5736
- Method : params . Method ,
5737
- Key : PathName ,
5738
- Query : params . Query ,
5739
- Headers : params . Headers ,
5740
- Expires : params . Expires
5741
- } ) ;
5742
- callback && callback ( { Authorization : Authorization } ) ;
5743
- return Authorization ;
5757
+ return function ( ) {
5758
+ var Authorization = util . getAuth ( {
5759
+ SecretId : params . SecretId || self . options . SecretId ,
5760
+ SecretKey : params . SecretKey || self . options . SecretKey ,
5761
+ Method : params . Method ,
5762
+ Key : PathName ,
5763
+ Query : params . Query ,
5764
+ Headers : params . Headers ,
5765
+ Expires : params . Expires
5766
+ } ) ;
5767
+ var AuthData = {
5768
+ Authorization : Authorization ,
5769
+ XCosSecurityToken : self . options . XCosSecurityToken
5770
+ } ;
5771
+ callback && callback ( AuthData ) ;
5772
+ return AuthData ;
5773
+ } ( ) ;
5744
5774
}
5745
5775
return '' ;
5746
5776
}
0 commit comments