作者 lyh

gx

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