|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
namespace Longyi\Core\Repositories;
|
|
namespace Longyi\Core\Repositories;
|
|
|
|
|
|
|
|
|
|
+use Aws\S3\S3Client;
|
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Http\UploadedFile;
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Support\Str;
|
|
@@ -99,14 +100,30 @@ class ProductImageRepository extends BaseProductImageRepository
|
|
|
*/
|
|
*/
|
|
|
protected function storeFile(UploadedFile $file, $product): string
|
|
protected function storeFile(UploadedFile $file, $product): string
|
|
|
{
|
|
{
|
|
|
- $directory = 'product/' . $product->id;
|
|
|
|
|
|
|
+ $directory = 'uploads/product/' . $product->id;
|
|
|
|
|
|
|
|
if (Str::contains($file->getMimeType(), 'image')) {
|
|
if (Str::contains($file->getMimeType(), 'image')) {
|
|
|
$manager = new ImageManager;
|
|
$manager = new ImageManager;
|
|
|
$image = $manager->make($file)->encode('webp');
|
|
$image = $manager->make($file)->encode('webp');
|
|
|
$path = $directory . '/' . Str::random(40) . '.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;
|
|
return $path;
|
|
|
}
|
|
}
|
|
|
|
|
|