secretId = $secretId; return $this; } /** * @param string $secretKey * @return $this */ public function secretKey(string $secretKey): self { $this->secretKey = $secretKey; return $this; } /** * @param string $region * @return $this */ public function region(string $region): self { $this->region = $region; return $this; } /** * @param string $bucket * @return $this */ public function bucket(string $bucket): self { $this->bucket = $bucket; return $this; } /** * @param string $object * @param string $filePath * @return bool */ public function upload(string $object, string $filePath): bool { $cosClient = new Client([ 'region' => $this->region, 'schema' => 'https', 'credentials' => [ 'secretId' => $this->secretId, 'secretKey' => $this->secretKey ] ]); $key = $object; $file = fopen($filePath, "rb"); if ($file) { $cosClient->putObject([ 'Bucket' => $this->bucket, 'Key' => $key, 'Body' => $file ]); return true; } return false; } }