BunnyWay / BunnyCDN.PHP.Storage

The official PHP library used for interacting with the BunnyCDN Storage API.
MIT License
68 stars 27 forks source link

How to upload files in batches? #6

Closed 2366621450 closed 7 months ago

rafael-at-bunny commented 7 months ago

If you are looking into parallel uploads, you can use GuzzleHttp\Promise (which since 2.1.0 this library depends on).

Example:

$promises = [];
foreach ($files_to_upload as $local_path => $remote_path) {
    $promise = new \GuzzleHttp\Promise\Promise(
        function () use (&$promise, $storage, $local_path, $remote_path) {
            /** @var \GuzzleHttp\Promise\Promise $promise */
            $promise->resolve($storage->upload($local_path, $remote_path));
        }
    );

    $promises[$remote_path] = $promise;
    unset($promise);
}

\GuzzleHttp\Promise\Utils::unwrap($promises);

If you are looking into passing a directory/array of files to the upload() method, that unfortunately isn't possible at the moment.