bianjunhui 5 дней назад
Родитель
Сommit
835a970911

+ 20 - 3
packages/Longyi/Core/src/Repositories/ProductImageRepository.php

@@ -2,6 +2,7 @@
 
 namespace Longyi\Core\Repositories;
 
+use Aws\S3\S3Client;
 use Illuminate\Http\UploadedFile;
 use Illuminate\Support\Facades\Storage;
 use Illuminate\Support\Str;
@@ -99,14 +100,30 @@ class ProductImageRepository extends BaseProductImageRepository
      */
     protected function storeFile(UploadedFile $file, $product): string
     {
-        $directory = 'product/' . $product->id;
+        $directory = 'uploads/product/' . $product->id;
 
         if (Str::contains($file->getMimeType(), 'image')) {
             $manager = new ImageManager;
             $image   = $manager->make($file)->encode('webp');
             $path    = $directory . '/' . Str::random(40) . '.webp';
-            Storage::put($path, $image);
-
+            //Storage::put($path, $image);
+            $s3Client = new S3Client([
+                'version' => 'latest',
+                'region'  => env('AWS_DEFAULT_REGION'),
+                'credentials' => [
+                    'key'    => env('AWS_ACCESS_KEY_ID'),
+                    'secret' => env('AWS_SECRET_ACCESS_KEY'),
+                ],
+                'http'    => [
+                    'verify' => false,  // 临时禁用 SSL 验证用于测试
+                ],
+            ]);
+             $s3Client->putObject([
+                'Bucket'      => env('AWS_BUCKET'),
+                'Key'         => $path,
+                'Body'        => (string) $image,
+                'ContentType' => 'image/webp',
+            ]);
             return $path;
         }
 

+ 1 - 1
packages/Webkul/Product/src/Repositories/ProductAttributeValueRepository.php

@@ -56,7 +56,7 @@ class ProductAttributeValueRepository extends Repository
 
             if (in_array($attribute->type, ['image', 'file'])) {
                 $data[$attribute->code] = gettype($data[$attribute->code]) === 'object'
-                    ? request()->file($attribute->code)->store('product/'.$product->id)
+                    ? request()->file($attribute->code)->store('uploads/product/'.$product->id)
                     : $data[$attribute->code];
             }
 

+ 1 - 1
packages/Webkul/Product/src/Repositories/ProductMediaRepository.php

@@ -34,7 +34,7 @@ class ProductMediaRepository extends Repository
      */
     public function getProductDirectory($product): string
     {
-        return 'uploads/'.date('Ym/d');
+        return 'uploads/product/' . $product->id;
     }
 
     /**