key = $key; return $this; } /** * @param string $secret * @return $this */ public function secret(string $secret): self { $this->secret = $secret; return $this; } /** * @param string $endpoint * @return $this */ public function endpoint(string $endpoint): self { $this->endpoint = $endpoint; 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 { // 创建ObsClient实例 $obsClient = new ObsClient([ 'key' => $this->key, 'secret' => $this->secret, 'endpoint' => $this->endpoint ]); $resp = $obsClient->putObject([ 'Bucket' => $this->bucket, 'Key' => $object, 'SourceFile' => $filePath // localfile为待上传的本地文件路径,需要指定到具体的文件名 ]); if (isset($resp['RequestId'])) { return true; } return false; } }