public static function TransFile($filePath, $request, $sourceFile = null, $conten_length = NULL) { try { $Trans = new TransLargeFile(); $Trans->getFileSize($filePath); $Trans->setContentLenght($conten_length); COMMONLOG(DEBUG, "send header:%s", $request->getURL()); $Trans->connectService($request); $Trans->sendHeader($request->getURL()); if (!$sourceFile) { $sourceFile = $filePath; } COMMONLOG(DEBUG, "source file:%s", $sourceFile); $Trans->sendFile($filePath); $result = $Trans->getResult(); $Trans->close(); return $result; } catch (Exception $e) { $Trans->close(); throw $e; } }
private function TransFile($mothed, $args) { include_once 'Obs/S3/Model/MultipartUpload/SetObjectHead.php'; $head = new \SetObjectHead(); $head->setObject($args[0]); $head->setAK(ObsClient::$configArr['key']); $head->setSK(ObsClient::$configArr['secret']); $head->setMothed('PUT'); if (array_key_exists("region", ObsClient::$configArr)) { $head->setregion(ObsClient::$configArr['region']); } if (array_key_exists("signature", ObsClient::$configArr)) { if (get_class(ObsClient::$configArr['signature']) == 'Obs\\S3\\S3Signature') { $head->setSignature('s3'); } elseif (get_class(ObsClient::$configArr['signature']) == 'Obs\\S3\\S3SignatureV4') { $head->setSignature('v4'); } } $endPointArr = explode('//', ObsClient::$configArr['endpoint']); $ssl = $endPointArr[0] === 'https:' ? true : false; $head->setHost($endPointArr[1], ObsClient::$configArr['path_style'], $ssl); include_once 'Obs/S3/Model/MultipartUpload/TransLargeFile.php'; $arr = \TransLargeFile::TransFile($args[0]['SourceFile'], $head, $this->sourceFile); include_once 'Obs/S3/Model/MultipartUpload/GetResult.php'; $a = new \GetResult($arr, ucfirst($mothed)); COMMONLOG(INFO, "http request:status:" . $a->status . ", code:" . $a->errCode . ", message:" . $a->errMsg); if (intval($a->status) > 300) { $S3Except = new S3Exception($a->errMsg); $S3Except->setExceptionCode($a->errCode); $S3Except->setExceptionType("Client"); $S3Except->setRequestId($a->requestId); $S3Except->setResponse(new Response($a->status)); throw $S3Except; // throw new \Exception("MOS Error Code: $a->errCode, Status Code: $a->status, MOS Request ID: $a->requestId, MOS Error Message:$a->errMsg "); } return new Model($a->requst); }