作者 lyh

gx

@@ -32,7 +32,7 @@ class CopyImageFileListener implements ShouldQueue @@ -32,7 +32,7 @@ class CopyImageFileListener implements ShouldQueue
32 if(!empty($imageList)){ 32 if(!empty($imageList)){
33 $amazonS3Service = new AmazonS3Service(); 33 $amazonS3Service = new AmazonS3Service();
34 foreach ($imageList as $k => $v){ 34 foreach ($imageList as $k => $v){
35 - $rs = $amazonS3Service->syncImageFiles(getImageUrl($v['path'])); 35 + $rs = $amazonS3Service->syncImageFiles(getImageUrl($v['path']),$v['size']);
36 $imageModel->edit(['is_cos'=>0],['id'=>$v['id']]); 36 $imageModel->edit(['is_cos'=>0],['id'=>$v['id']]);
37 @file_put_contents(storage_path('logs/lyh_error.log'), var_export('图片:'.$rs, true) . PHP_EOL, FILE_APPEND); 37 @file_put_contents(storage_path('logs/lyh_error.log'), var_export('图片:'.$rs, true) . PHP_EOL, FILE_APPEND);
38 } 38 }
@@ -44,7 +44,7 @@ class CopyImageFileListener implements ShouldQueue @@ -44,7 +44,7 @@ class CopyImageFileListener implements ShouldQueue
44 if(!empty($fileList)){ 44 if(!empty($fileList)){
45 $amazonS3Service = new AmazonS3Service(); 45 $amazonS3Service = new AmazonS3Service();
46 foreach ($fileList as $k => $v){ 46 foreach ($fileList as $k => $v){
47 - $amazonS3Service->syncImageFiles(getImageUrl($v['path'])); 47 + $amazonS3Service->syncImageFiles(getImageUrl($v['path']),$v['size']);
48 $fileList->edit(['is_cos'=>0],['id'=>$v['id']]); 48 $fileList->edit(['is_cos'=>0],['id'=>$v['id']]);
49 @file_put_contents(storage_path('logs/lyh_error.log'), var_export('文件:'.$v['id'], true) . PHP_EOL, FILE_APPEND); 49 @file_put_contents(storage_path('logs/lyh_error.log'), var_export('文件:'.$v['id'], true) . PHP_EOL, FILE_APPEND);
50 } 50 }
@@ -64,7 +64,7 @@ class AmazonS3Service @@ -64,7 +64,7 @@ class AmazonS3Service
64 * @method :post 64 * @method :post
65 * @time :2024/1/23 9:20 65 * @time :2024/1/23 9:20
66 */ 66 */
67 - public function syncImageFiles($files) 67 + public function syncImageFiles($files,$size)
68 { 68 {
69 $key = str_replace_url($files); 69 $key = str_replace_url($files);
70 // try { 70 // try {
@@ -83,12 +83,11 @@ class AmazonS3Service @@ -83,12 +83,11 @@ class AmazonS3Service
83 if ($file_handle === false) { 83 if ($file_handle === false) {
84 return '无法打开文件'; 84 return '无法打开文件';
85 } 85 }
86 - $content_length = filesize($files);  
87 $result = $this->s3->putObject([ 86 $result = $this->s3->putObject([
88 'Bucket' => $this->bucket, 87 'Bucket' => $this->bucket,
89 'Key' => $key, 88 'Key' => $key,
90 'Body' => $file_handle, 89 'Body' => $file_handle,
91 - 'ContentLength' => $content_length 90 + 'ContentLength' => $size
92 ]); 91 ]);
93 return $result['ObjectURL']; 92 return $result['ObjectURL'];
94 // } catch (AwsException $e) { 93 // } catch (AwsException $e) {