|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace Webkul\Product\Repositories;
|
|
|
|
|
|
+use Aws\S3\S3Client;
|
|
|
use Exception;
|
|
|
use Illuminate\Http\UploadedFile;
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
@@ -33,7 +34,7 @@ class ProductMediaRepository extends Repository
|
|
|
*/
|
|
|
public function getProductDirectory($product): string
|
|
|
{
|
|
|
- return 'product/'.$product->id;
|
|
|
+ return 'uploads/'.date('Ym/d');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -60,8 +61,27 @@ class ProductMediaRepository extends Repository
|
|
|
$image = $manager->make($file)->encode('webp');
|
|
|
|
|
|
$path = $this->getProductDirectory($product).'/'.Str::random(40).'.webp';
|
|
|
+ //Storage::put($path, $image);
|
|
|
+ // 方式一:使用原生 AWS SDK 绕过 Laravel Storage
|
|
|
+ $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 验证用于测试
|
|
|
+ ],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $result = $s3Client->putObject([
|
|
|
+ 'Bucket' => env('AWS_BUCKET'),
|
|
|
+ 'Key' => $path,
|
|
|
+ 'Body' => (string) $image,
|
|
|
+ 'ContentType' => 'image/webp',
|
|
|
+ ]);
|
|
|
|
|
|
- Storage::put($path, $image);
|
|
|
} else {
|
|
|
$path = $file->store($this->getProductDirectory($product));
|
|
|
}
|