@@ -283,8 +283,10 @@ private function uploadV2($fname, $blkputRets = null)
283283 $ uploaded = 0 ;
284284 $ partNumber = 1 ;
285285 $ encodedObjectName = $ this ->key ? \Qiniu \base64_urlSafeEncode ($ this ->key ) : '~ ' ;
286-
287286 $ isResumeUpload = $ blkputRets !== null ;
287+
288+ // 初始化 upload id
289+ $ err = null ;
288290 if ($ blkputRets ) {
289291 if (isset ($ blkputRets ["etags " ]) && isset ($ blkputRets ["uploadId " ]) &&
290292 isset ($ blkputRets ["expiredAt " ]) && $ blkputRets ["expiredAt " ] > time () &&
@@ -298,12 +300,16 @@ private function uploadV2($fname, $blkputRets = null)
298300 $ uploaded = $ blkputRets ["uploaded " ];
299301 $ partNumber = count ($ this ->finishedEtags ["etags " ]) + 1 ;
300302 } else {
301- $ this ->makeInitReq ($ encodedObjectName );
303+ $ err = $ this ->makeInitReq ($ encodedObjectName );
302304 }
303305 } else {
304- $ this ->makeInitReq ($ encodedObjectName );
306+ $ err = $ this ->makeInitReq ($ encodedObjectName );
307+ }
308+ if ($ err != null ) {
309+ return array (null , $ err );
305310 }
306311
312+ // 上传分片
307313 fseek ($ this ->inputStream , $ uploaded );
308314 while ($ uploaded < $ this ->size ) {
309315 $ blockSize = $ this ->blockSize ($ uploaded );
@@ -452,9 +458,15 @@ private function blockSize($uploaded)
452458
453459 private function makeInitReq ($ encodedObjectName )
454460 {
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 ;
458470 }
459471
460472 /**
@@ -468,7 +480,12 @@ private function initReq($encodedObjectName)
468480 'Content-Type ' => 'application/json '
469481 );
470482 $ 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 ));
472489 }
473490
474491 /**
0 commit comments