作者 lyh

gx

@@ -166,7 +166,7 @@ class ImageController extends Controller @@ -166,7 +166,7 @@ class ImageController extends Controller
166 return $this->response('添加失败', Code::USER_ERROR); 166 return $this->response('添加失败', Code::USER_ERROR);
167 } 167 }
168 $cos = new TencentCosService(); 168 $cos = new TencentCosService();
169 - return $cos->uploadToCos($files,$this->path,$fileName); 169 + return $cos->uploadToCos($this->path,$fileName);
170 return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]); 170 return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]);
171 } 171 }
172 172
@@ -44,13 +44,13 @@ class TencentCosService extends BaseService @@ -44,13 +44,13 @@ class TencentCosService extends BaseService
44 * @method :post 44 * @method :post
45 * @time :2023/7/19 14:47 45 * @time :2023/7/19 14:47
46 */ 46 */
47 - public function uploadToCos($file,$path,$filename) 47 + public function uploadToCos($path,$filename)
48 { 48 {
49 $objectKey = $path.'/'.$filename; 49 $objectKey = $path.'/'.$filename;
50 // 上传到腾讯云 COS 50 // 上传到腾讯云 COS
51 $httpClient = new Client(); 51 $httpClient = new Client();
52 $response = $httpClient->request('PUT', "https://{$this->config['bucket']}.cos.{$this->config['cosRegion']}.myqcloud.com/{$objectKey}", [ 52 $response = $httpClient->request('PUT', "https://{$this->config['bucket']}.cos.{$this->config['cosRegion']}.myqcloud.com/{$objectKey}", [
53 - 'body' => file_get_contents($file->getRealPath()), 53 + 'body' => file_get_contents(config('filesystems.disks.upload')['root'].$objectKey),
54 'headers' => $this->generateHeaders($this->config['secretId'], $this->config['secretKey']), 54 'headers' => $this->generateHeaders($this->config['secretId'], $this->config['secretKey']),
55 ]); 55 ]);
56 // 若上传成功,则返回上传后的 URL 56 // 若上传成功,则返回上传后的 URL