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

Set "Share publicly" after uploading #22

Closed
weehong opened this issue Dec 6, 2017 · 3 comments
Closed

Set "Share publicly" after uploading #22

weehong opened this issue Dec 6, 2017 · 3 comments

Comments

@weehong
Copy link

weehong commented Dec 6, 2017

May I know is that possible to set the file to "Share publicly" after uploading the file and obtain the public link?

@regiszanandrea
Copy link
Contributor

Please, see: #30

@ro0t
Copy link

ro0t commented Mar 27, 2018

// This function will return the location + stored name from Google Storage
$disk = Storage::disk('gcs')->put($location, $image);

// Pass in the disk variable, and then the visibility.
Storage::disk('gcs')->setVisibility($disk, 'public');

This works for me @weehong

@vinay-vissh
Copy link

vinay-vissh commented Apr 12, 2018

@ro0t Thanks for the idea.
It made me go through \Superbalist\LaravelGoogleCloudStorage\GoogleCloudStorageServiceProvider - which made me realise that the value of 'visibility' for the gs disk in config('filesystems') is not used at all.

(My bad - I assumed that, like other packages, this one also supports 'visibility' config field)

Ended up making this simple function. It gets the job done in a single request to Google storage.

/**
 * @param string $location
 * @param HttpFile|UploadedFile $file
 * @param string $fileName
 *
 * @return null
 */
public static function storeInDefaultDisk($location, $file, $fileName)
{
    // Visibility issue:
    // > \Superbalist\LaravelGoogleCloudStorage\GoogleCloudStorageServiceProvider, which is used for Google Storage,
    //     does not use the value of 'visibility' for the gs disk in config('filesystems')
    // > So, lets just pass this ignored config as 4th argument in Storage::putFileAs()
    //
    $options = [];

    $visibility = config('filesystems.disks.' . config('filesystems.default') . '.visibility');
    if( $visibility != null ){
        $options['visibility'] = $visibility;
    }

    /*$pathUploadedFile =*/ \Storage::putFileAs($location, $file, $fileName, $options);

    return;
}

Google Compute Engine service-account has 'Read Write' access for Storage.
Using v2.0.0 of this package.

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

No branches or pull requests

5 participants