Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Dynamic driver instance for different buckets #23

Closed
eodin opened this issue Jan 5, 2018 · 1 comment
Closed

Dynamic driver instance for different buckets #23

eodin opened this issue Jan 5, 2018 · 1 comment
Labels

Comments

@eodin
Copy link

eodin commented Jan 5, 2018

I need to access different buckets dynamically depending on params

$param = parse_url('gs://mybucket/path/to/file');
Config::set('filesystems.disks.gcs.bucket', $param['host']); // maybe works
$file = Storage::disk('gcs')->get($param['path']);

Or something like

$storage = Storage::createS3Driver([
    'driver' => 's3',
    'key'    => 'your-key',
    'secret' => 'your-secret',
    'region' => 'us-east-1',
    'bucket' => $bucketName,
]);
@zoidyzoidzoid
Copy link
Contributor

zoidyzoidzoid commented Jan 5, 2018

The only dynamic stuff we do is for different env vars in different environments using the following in Laravel's config/storage.php:

        'connections' => array(
                // ...
                'gcloud' => array(
                        'adapter' => 'gcloud',
                        'bucket' => env('STORAGE_GCLOUD_BUCKET'),
                ),
        ),

But if you need the dynamic buckets at runtime, I'd suggest you fork flystem-google-cloud-storage to support different buckets for write

Or you could just generate a Google\Cloud\Storage\StorageClient, and then dynamic buckets from that client the way we instantiate the bucket here, doing something like:

$storageClient = new StorageClient([
    'projectId' => $projectId,
    'keyFilePath' => $keyFile,
]);
$bucket = $storageClient->bucket($bucketName);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants