Просмотр исходного кода

fix: 修改华为创建桶和设置跨域

Gosowong 2 лет назад
Родитель
Сommit
ab6b53eabe

+ 4 - 3
crmeb/crmeb/services/upload/extend/obs/Client.php

@@ -255,7 +255,7 @@ class Client extends BaseClient
         ];
 
         $res = $this->request('https://' . $header['Host'] . '/', 'PUT', [
-            'bucket' => $bucket
+            'Location' => $region
         ], $header);
 
         return $this->response($res);
@@ -335,9 +335,10 @@ class Client extends BaseClient
     {
         $header = [
             'Host' => $this->getRequestUrl($bucket, $region),
+            'content-md5' => base64_encode(md5(json_encode($data), true))
         ];
-        $xml = $this->xmlBuild($data, 'CORSConfiguration', '');
-        $res = $this->request('https://' . $header['Host'] . '/', 'PUT', [
+        $xml = $this->xmlBuild($data, 'CORSConfiguration', 'CORSRule');
+        $res = $this->request('https://' . $header['Host'] . '/cors ', 'PUT', [
             'bucket' => $bucket,
             'body' => $xml
         ], $header);

+ 7 - 6
crmeb/crmeb/services/upload/storage/Obs.php

@@ -3,6 +3,7 @@
 namespace crmeb\services\upload\storage;
 
 use crmeb\exceptions\AdminException;
+use crmeb\exceptions\UploadException;
 use crmeb\services\upload\extend\obs\Client as TyClient;
 use crmeb\services\upload\BaseUpload;
 
@@ -220,12 +221,12 @@ class Obs extends BaseUpload
     public function setBucketCors(string $name, string $region)
     {
         try {
-            $res = $this->app()->PutBucketCors($name, $region, [
-                'AllowedHeaders' => ['*'],
-                'AllowedMethods' => ['PUT', 'GET', 'POST', 'DELETE', 'HEAD'],
-                'AllowedOrigins' => ['*'],
-                'ExposeHeaders' => ['ETag', 'Content-Length', 'x-cos-request-id'],
-                'MaxAgeSeconds' => 12
+            $this->app()->PutBucketCors($name, $region, [
+                'AllowedHeader' => ['*'],
+                'AllowedMethod' => ['PUT', 'GET', 'POST', 'DELETE', 'HEAD'],
+                'AllowedOrigin' => ['*'],
+                'ExposeHeader' => ['ETag', 'Content-Length', 'x-cos-request-id'],
+                'MaxAgeSeconds' => 100
             ]);
             return true;
         } catch (\Throwable $e) {