From b21028a3bf5318b68402fcc6d9416c6f049ebab4 Mon Sep 17 00:00:00 2001 From: Jon Gilkison Date: Fri, 11 Jan 2019 00:29:21 +0700 Subject: [PATCH] Support for prefix and delimiter in listing files. --- src/Client.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Client.php b/src/Client.php index d58e140..1bbe217 100644 --- a/src/Client.php +++ b/src/Client.php @@ -297,15 +297,25 @@ public function listFiles(array $options) // B2 returns, at most, 1000 files per "page". Loop through the pages and compile an array of File objects. while (true) { + $json = [ + 'bucketId' => $options['BucketId'], + 'startFileName' => $nextFileName, + 'maxFileCount' => $maxFileCount, + ]; + + if (isset($options['prefix'])) { + $json['prefix'] = $options['prefix']; + } + + if (isset($options['delimiter'])) { + $json['delimiter'] = $options['delimiter']; + } + $response = $this->client->request('POST', $this->apiUrl.'/b2_list_file_names', [ 'headers' => [ 'Authorization' => $this->authToken ], - 'json' => [ - 'bucketId' => $options['BucketId'], - 'startFileName' => $nextFileName, - 'maxFileCount' => $maxFileCount, - ] + 'json' => $json ]); foreach ($response['files'] as $file) {