public function testWithStorage() { $storage = new StorageClient(); $bucket = $storage->bucket('test-bucket'); $object = $bucket->object('test-object.jpg'); $gcsUri = 'gs://test-bucket/test-object.jpg'; $image = new Image($object, ['landmarks']); $res = $image->requestObject(); $this->assertEquals($res['image']['source']['gcsImageUri'], $gcsUri); $this->assertEquals($res['features'], [['type' => 'LANDMARK_DETECTION']]); }
/** * Returns Google Cloud Storage filesystem * * @return object Google Cloud Storage */ protected function __getGCSFilesystem() { $config = Config::getInstance(); $project_id = $config->get('storage.gcs.project_id'); $auth_json = $config->get('storage.gcs.auth_json'); $bucket_name = $config->get('storage.gcs.bucket'); $prefix = $config->get('storage.gcs.prefix'); if (!$project_id || !$auth_json || !$bucket_name) { return null; } // Init Google Cloud Storage client $client = new StorageClient(['projectId' => $project_id, 'keyFile' => json_decode($auth_json, true)]); // Get bucket object $bucket = $client->bucket($bucket_name); // Init adapter $adapter = new GoogleStorageAdapter($client, $bucket, $prefix); // Return Google Cloud Storage filesystem return new FlyFilesystem($adapter, ['visibility' => AdapterInterface::VISIBILITY_PUBLIC]); }
/** * CloudStorage constructor. * * @param string $projectId The Google Cloud project id * @param string $bucketName The cloud storage bucket name */ public function __construct($projectId, $bucketName) { $storage = new StorageClient(['projectId' => $projectId]); $this->bucket = $storage->bucket($bucketName); }