From 285b3ca92b88ff59cebc3a583028b2e3cd03cb8d Mon Sep 17 00:00:00 2001 From: Gosowong <1329847115@qq.com> Date: Thu, 8 Jun 2023 14:04:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E5=8D=8E=E4=B8=BA?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=A1=B6=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/v1/setting/SystemStorage.php | 5 ++++- crmeb/crmeb/services/upload/extend/obs/Client.php | 14 +++++++++----- crmeb/crmeb/services/upload/storage/Obs.php | 12 +++++------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/crmeb/app/adminapi/controller/v1/setting/SystemStorage.php b/crmeb/app/adminapi/controller/v1/setting/SystemStorage.php index cdbefab4a..853bbea62 100644 --- a/crmeb/app/adminapi/controller/v1/setting/SystemStorage.php +++ b/crmeb/app/adminapi/controller/v1/setting/SystemStorage.php @@ -166,7 +166,10 @@ class SystemStorage extends AuthController //设置跨域规则 try { $upload = UploadService::init($info->type); - $upload->setBucketCors($info->name, $info->region); + $res = $upload->setBucketCors($info->name, $info->region); + if (false === $res) { + return app('json')->fail($upload->getError()); + } } catch (\Throwable $e) { } diff --git a/crmeb/crmeb/services/upload/extend/obs/Client.php b/crmeb/crmeb/services/upload/extend/obs/Client.php index 5cdfd7cd0..b33ba9bb6 100644 --- a/crmeb/crmeb/services/upload/extend/obs/Client.php +++ b/crmeb/crmeb/services/upload/extend/obs/Client.php @@ -252,10 +252,12 @@ class Client extends BaseClient $header = [ 'x-obs-acl' => $acl, 'Host' => $this->getRequestUrl($bucket, $region), + "Content-Type" => "application/xml" ]; - + $xml = "{$region}"; $res = $this->request('https://' . $header['Host'] . '/', 'PUT', [ - 'Location' => $region + 'bucket' => $bucket, + 'body' => $xml ], $header); return $this->response($res); @@ -333,12 +335,14 @@ class Client extends BaseClient */ public function putBucketCors(string $bucket, string $region, array $data = []) { + $xml = $this->xmlBuild($data, 'CORSConfiguration', 'CORSRule'); $header = [ 'Host' => $this->getRequestUrl($bucket, $region), - 'content-md5' => base64_encode(md5(json_encode($data), true)) + 'Content-Type' => 'application/xml', + 'Content-Length' => strlen($xml), + 'Content-MD5' => base64_encode(md5($xml, true)) ]; - $xml = $this->xmlBuild($data, 'CORSConfiguration', 'CORSRule'); - $res = $this->request('https://' . $header['Host'] . '/cors ', 'PUT', [ + $res = $this->request('https://' . $header['Host'] . '/cors', 'PUT', [ 'bucket' => $bucket, 'body' => $xml ], $header); diff --git a/crmeb/crmeb/services/upload/storage/Obs.php b/crmeb/crmeb/services/upload/storage/Obs.php index 643f53b67..686b5c63f 100644 --- a/crmeb/crmeb/services/upload/storage/Obs.php +++ b/crmeb/crmeb/services/upload/storage/Obs.php @@ -6,6 +6,7 @@ use crmeb\exceptions\AdminException; use crmeb\exceptions\UploadException; use crmeb\services\upload\extend\obs\Client as TyClient; use crmeb\services\upload\BaseUpload; +use GuzzleHttp\Psr7\Utils; class Obs extends BaseUpload { @@ -70,7 +71,8 @@ class Obs extends BaseUpload } $key = $this->saveFileName($fileHandle->getRealPath(), $fileHandle->getOriginalExtension()); - $body = $fileHandle->getRealPath(); + $body = fopen($fileHandle->getRealPath(), 'rb'); + $body = (string)Utils::streamFor($body); } else { $key = $file; $body = $fileContent; @@ -78,7 +80,7 @@ class Obs extends BaseUpload $key = $this->getUploadPath($key); try { - $uploadInfo = $this->app()->putObject($key, $body); + $uploadInfo = $this->app()->putObject($key, $body, 'application/octet-stream'); $this->fileInfo->uploadInfo = $uploadInfo; $this->fileInfo->realName = $fileHandle->getOriginalName(); $this->fileInfo->filePath = ($this->cdn ?: $this->uploadUrl) . '/' . $key; @@ -205,17 +207,13 @@ class Obs extends BaseUpload { $parseDomin = parse_url($domain); try { - $this->app()->putBucketDomain($name, '', [ + $this->app()->putBucketDomain($name, $region, [ 'domainname' => $parseDomin['host'], ]); return true; } catch (\Throwable $e) { - if ($message = $this->setMessage($e->getMessage())) { - return $this->setError($message); - } return $this->setError($e->getMessage()); } - return false; } public function setBucketCors(string $name, string $region)