@@ -283,8 +283,10 @@ private function uploadV2($fname, $blkputRets = null)
283
283
$ uploaded = 0 ;
284
284
$ partNumber = 1 ;
285
285
$ encodedObjectName = $ this ->key ? \Qiniu \base64_urlSafeEncode ($ this ->key ) : '~ ' ;
286
-
287
286
$ isResumeUpload = $ blkputRets !== null ;
287
+
288
+ // 初始化 upload id
289
+ $ err = null ;
288
290
if ($ blkputRets ) {
289
291
if (isset ($ blkputRets ["etags " ]) && isset ($ blkputRets ["uploadId " ]) &&
290
292
isset ($ blkputRets ["expiredAt " ]) && $ blkputRets ["expiredAt " ] > time () &&
@@ -298,12 +300,16 @@ private function uploadV2($fname, $blkputRets = null)
298
300
$ uploaded = $ blkputRets ["uploaded " ];
299
301
$ partNumber = count ($ this ->finishedEtags ["etags " ]) + 1 ;
300
302
} else {
301
- $ this ->makeInitReq ($ encodedObjectName );
303
+ $ err = $ this ->makeInitReq ($ encodedObjectName );
302
304
}
303
305
} else {
304
- $ this ->makeInitReq ($ encodedObjectName );
306
+ $ err = $ this ->makeInitReq ($ encodedObjectName );
307
+ }
308
+ if ($ err != null ) {
309
+ return array (null , $ err );
305
310
}
306
311
312
+ // 上传分片
307
313
fseek ($ this ->inputStream , $ uploaded );
308
314
while ($ uploaded < $ this ->size ) {
309
315
$ blockSize = $ this ->blockSize ($ uploaded );
@@ -452,9 +458,15 @@ private function blockSize($uploaded)
452
458
453
459
private function makeInitReq ($ encodedObjectName )
454
460
{
455
- $ res = $ this ->initReq ($ encodedObjectName );
456
- $ this ->finishedEtags ["uploadId " ] = $ res ['uploadId ' ];
457
- $ this ->finishedEtags ["expiredAt " ] = $ res ['expireAt ' ];
461
+ list ($ ret , $ err ) = $ this ->initReq ($ encodedObjectName );
462
+
463
+ if ($ ret == null ) {
464
+ return $ err ;
465
+ }
466
+
467
+ $ this ->finishedEtags ["uploadId " ] = $ ret ['uploadId ' ];
468
+ $ this ->finishedEtags ["expiredAt " ] = $ ret ['expireAt ' ];
469
+ return $ err ;
458
470
}
459
471
460
472
/**
@@ -468,7 +480,12 @@ private function initReq($encodedObjectName)
468
480
'Content-Type ' => 'application/json '
469
481
);
470
482
$ response = $ this ->postWithHeaders ($ url , null , $ headers );
471
- return $ response ->json ();
483
+ $ ret = $ response ->json ();
484
+ if ($ response ->ok () && $ ret != null ) {
485
+ return array ($ ret , null );
486
+ }
487
+
488
+ return array (null , new Error ($ url , $ response ));
472
489
}
473
490
474
491
/**
0 commit comments