Code Monkey home page Code Monkey logo

laravel-google-cloud-storage's Introduction

laravel-google-cloud-storage

A Google Cloud Storage filesystem for Laravel.

Author Build Status Software License Packagist Version Total Downloads

This package is a wrapper bridging flysystem-google-storage into Laravel as an available storage disk.

Installation

composer require superbalist/laravel-google-cloud-storage

If you are on Laravel 5.4 or earlier, then register the service provider in app.php

'providers' => [
    // ...
    Superbalist\LaravelGoogleCloudStorage\GoogleCloudStorageServiceProvider::class,
]

If you are on Laravel 5.5 or higher, composer will have registered the provider automatically for you.

Add a new disk to your filesystems.php config

'gcs' => [
    'driver' => 'gcs',
    'project_id' => env('GOOGLE_CLOUD_PROJECT_ID', 'your-project-id'),
    'key_file' => env('GOOGLE_CLOUD_KEY_FILE', null), // optional: /path/to/service-account.json
    'bucket' => env('GOOGLE_CLOUD_STORAGE_BUCKET', 'your-bucket'),
    'path_prefix' => env('GOOGLE_CLOUD_STORAGE_PATH_PREFIX', null), // optional: /default/path/to/apply/in/bucket
    'storage_api_uri' => env('GOOGLE_CLOUD_STORAGE_API_URI', null), // see: Public URLs below
    'visibility' => 'public', // optional: public|private
],

Authentication

The Google Client uses a few methods to determine how it should authenticate with the Google API.

  1. If you specify a path in the key key_file in disk config, that json credentials file will be used.

  2. If the GOOGLE_APPLICATION_CREDENTIALS env var is set, it will use that.

    putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json');
  3. It will then try load the key file from a 'well known path':

    • windows: %APPDATA%/gcloud/application_default_credentials.json
    • others: $HOME/.config/gcloud/application_default_credentials.json
  4. If running in Google App Engine, the built-in service account associated with the application will be used.

  5. If running in Google Compute Engine, the built-in service account associated with the virtual machine instance will be used.

  6. If you want to authenticate directly without using a json file, you can specify an array for key_file in disk config with this data:

    'key_file' => [
        'type' => env('GOOGLE_CLOUD_ACCOUNT_TYPE'),
        'private_key_id' => env('GOOGLE_CLOUD_PRIVATE_KEY_ID'),
        'private_key' => env('GOOGLE_CLOUD_PRIVATE_KEY'),
        'client_email' => env('GOOGLE_CLOUD_CLIENT_EMAIL'),
        'client_id' => env('GOOGLE_CLOUD_CLIENT_ID'),
        'auth_uri' => env('GOOGLE_CLOUD_AUTH_URI'),
        'token_uri' => env('GOOGLE_CLOUD_TOKEN_URI'),
        'auth_provider_x509_cert_url' => env('GOOGLE_CLOUD_AUTH_PROVIDER_CERT_URL'),
        'client_x509_cert_url' => env('GOOGLE_CLOUD_CLIENT_CERT_URL'),
    ],

Public URLs

The adapter implements a getUrl($path) method which returns a public url to a file.

Note: Method available for Laravel 5.2 and higher. If used on 5.1, it will throw an exception.

$disk = Storage::disk('gcs');
$url = $disk->url('folder/my_file.txt');
>>> http://storage.googleapis.com/bucket-name/folder/my_file.txt

If you configure a path_prefix in your config:

$disk = Storage::disk('gcs');
$url = $disk->url('folder/my_file.txt');
>>> http://storage.googleapis.com/bucket-name/path-prefix/folder/my_file.txt

If you configure a custom storage_api_uri in your config:

$disk = Storage::disk('gcs');
$url = $disk->url('folder/my_file.txt');
>>> http://your-custom-domain.com/bucket-name/path-prefix/folder/my_file.txt

For a custom domain (storage api uri), you will need to configure a CNAME DNS entry pointing to storage.googleapis.com.

Please see https://cloud.google.com/storage/docs/xml-api/reference-uris#cname for further instructions.

Usage

$disk = Storage::disk('gcs');

// create a file
$disk->put('avatars/1', $fileContents);

// check if a file exists
$exists = $disk->exists('file.jpg');

// get file modification date
$time = $disk->lastModified('file1.jpg');

// copy a file
$disk->copy('old/file1.jpg', 'new/file1.jpg');

// move a file
$disk->move('old/file1.jpg', 'new/file1.jpg');

// get url to file
$url = $disk->url('folder/my_file.txt');

// Set the visibility of file to public
$disk->setVisibility('folder/my_file.txt', 'public');


// See https://laravel.com/docs/5.3/filesystem for full list of available functionality

laravel-google-cloud-storage's People

Contributors

casperlaitw avatar dgoguerra avatar jbaron-mx avatar jeroen-groenveld avatar johnmarkmassey avatar leewillis77 avatar matthewgoslett avatar mombuyish avatar necenzurat avatar nicja avatar pierlon avatar regiszanandrea avatar rommni avatar shad0wfir3 avatar sinkcup avatar zoidyzoidzoid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-google-cloud-storage's Issues

Dynamic driver instance for different buckets

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,
]);

Can't Delete Directory Laravel 5.4

I try delete a sub-directory of my Google Cloud Storage, but give me a error.

$disk = Storage::disk('gcs');
$dir = 'directory/2/otherdir/3'; <- i need delete this directory

$disk->deleteDirectory($dir);

I HAVE THIS RETURN

[19:35:45] LOG.error: Google\Cloud\Core\Exception\NotFoundException: {
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "Not Found"
   }
  ],
  "code": 404,
  "message": "Not Found"
 }
}
 in /Users/pablo/Sistemas/clientsystem/vendor/google/cloud/src/Core/RequestWrapper.php:241

Estimated google cloud storage price?

I know this is way off-topic, but I'm very limited in terms of founds and I can't even start testing using google cloud storage as my storage folder for my laravel project. So I'm asking if anyone of you had experiences about how mutch does it cost usually? My project would have an upload section with about 10 images / day uploaded and stored. These pictures are between 2MB and 5MB normally, but I reduce the size once they are uploaded to 300-500 kbyte. And these pictures are viewed about 30-40 times / month.

So anyone has experience?

404 Not Found Error Response

I get the response
https://www.googleapis.com/upload/storage/v1/b//o?predefinedAcl=projectPrivate&uploadType=multipart

Resulted in a

404 Not Found response: Not Found

When I try uploading a file to google cloud storage

folders?

Are there any methods to deal with folders?
like, delete or rename?

Question: how to make the uploaded image public after uploading

Hey, I have a question. I am trying to upload image and make it public. I've made the right permissions to my bucket but for some reason I am getting exception:

{
"error": {
"errors": [
{
"domain": "global",
"reason": "insufficientPermissions",
"message": "Insufficient Permission"
}
],
"code": 403,
"message": "Insufficient Permission"
}
}

This is how I upload and it gives me the above error:

foreach($request->file('post_image') as $image){
               $filename = $post->id.'_'.$i.'.jpg';
               $location = 'posts/'.$post->id;
               $storage = Storage::disk('gcs')->setVisibility($filename, 'public')->put($location, $image);
               $i++;
}

But it works like this:

foreach($request->file('post_image') as $image){
               $filename = $post->id.'_'.$i.'.jpg';
               $location = 'posts/'.$post->id;
               $storage = Storage::disk('gcs')->put($location, $image);
               $i++;
}

Custom Domain URI

Looks like I can only set a domain to go directly to a bucket. Because of this, the ->url() method will return https://domain.com/domain.com/file.ext. -- the second domain.com being the bucket.

If I try to do domain.com/bucket_name/file.ext, I get permission denied even though the file is public.

Am I missing something?

Put method memory leak

Hello, put/putFileAs methods might be leaking memory. Using mentioned methods in a looped command increases used memory every iteration. Used memory in every iteration:

4640056
13303408
21298416

Memory usage testing with Tinker:

>>> memory_get_usage()
=> 15369200
>>> \Storage::disk('tmp')->put('a', str_repeat("b", 1024*1024))
=> true
>>> memory_get_usage()
=> 18014216
>>> \Storage::disk('tmp')->put('a', str_repeat("b", 1024*1024))
=> true
>>> memory_get_usage()
=> 18016440
>>> \Storage::disk('tmp')->put('a', str_repeat("b", 1024*1024))
=> true
>>> memory_get_usage()
=> 18018664
>>> \Storage::disk('tmp')->put('a', str_repeat("b", 1024*1024))
=> true
>>> memory_get_usage()
=> 18020888
>>> \Storage::disk('tmp')->put('a', str_repeat("b", 1024*1024))
=> true
>>> memory_get_usage()
=> 18023112
>>> \Storage::disk('tmp')->put('a', str_repeat("b", 1024*1024))
=> true
>>> memory_get_usage()
=> 18025336
>>> \Storage::disk('tmp')->put('a', str_repeat("b", 1024*1024))
=> true
>>> memory_get_usage()
=> 18027560
>>> \Storage::disk('tmp')->put('a', str_repeat("b", 1024*1024))
=> true
>>> memory_get_usage()
=> 18029784

Not using the mentioned methods does not increase used memory every iteration.

File download

Hi there,

I proceed to download the file from the Cloud Storage with the code:
$file = Storage::disk('gcs')->get($fileData->path); header('Content-Disposition: attachment; filename="'.$fileData->filename.'"'); readfile($file);

But it don't work. What's the best way to do it?

Latest commit breaks built-in service account

Everything was working properly before for over a year, however it seems the latest commit breaks when not using a json key file because Laravel by default throws a warning when merging null with an array

This code:

return new StorageClient([ 'projectId' => $config['project_id'], 'keyFile' => array_merge([ "project_id" => $config['project_id'] ], array_get($config, 'key_file', [])) ]);

throws an error. In all cases where a key_file doesn't exist, it is set to null. This throws a

`ErrorException thrown with message "array_merge(): Argument #2 is not an array"

Stacktrace:
#59 ErrorException in /var/www/html/test-project/vendor/superbalist/laravel-google-cloud-storage/src/GoogleCloudStorageServiceProvider.php:98
#58 array_merge in /var/www/html/test-project/vendor/superbalist/laravel-google-cloud-storage/src/GoogleCloudStorageServiceProvider.php:98
#57 Superbalist\LaravelGoogleCloudStorage\GoogleCloudStorageServiceProvider:createClient in /var/www/html/test-project/vendor/superbalist/laravel-google-cloud-storage/src/GoogleCloudStorageServiceProvider.php:67
#56 Superbalist\LaravelGoogleCloudStorage\GoogleCloudStorageServiceProvider:Superbalist\LaravelGoogleCloudStorage{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php:139
#55 Illuminate\Filesystem\FilesystemManager:callCustomCreator in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php:119
#54 Illuminate\Filesystem\FilesystemManager:resolve in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php:103
#53 Illuminate\Filesystem\FilesystemManager:get in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php:80
#52 Illuminate\Filesystem\FilesystemManager:disk in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:237
#51 Illuminate\Support\Facades\Facade:__callStatic in /var/www/html/test-project/app/Http/Controllers/RecordingController.php:24
#50 App\Http\Controllers\RecordingController:getRecording in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
#49 call_user_func_array in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
#48 Illuminate\Routing\Controller:callAction in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:45
#47 Illuminate\Routing\ControllerDispatcher:dispatch in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Route.php:219
#46 Illuminate\Routing\Route:runController in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Route.php:176
#45 Illuminate\Routing\Route:run in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Router.php:680
#44 Illuminate\Routing\Router:Illuminate\Routing{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
#43 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php:41
#42 Illuminate\Routing\Middleware\SubstituteBindings:handle in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#41 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#40 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:75
#39 Illuminate\Foundation\Http\Middleware\VerifyCsrfToken:handle in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#38 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#37 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49
#36 Illuminate\View\Middleware\ShareErrorsFromSession:handle in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#35 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#34 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:56
#33 Illuminate\Session\Middleware\StartSession:handle in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#32 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#31 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37
#30 Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse:handle in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#29 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#28 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:66
#27 Illuminate\Cookie\Middleware\EncryptCookies:handle in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#26 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#25 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:104
#24 Illuminate\Pipeline\Pipeline:then in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Router.php:682
#23 Illuminate\Routing\Router:runRouteWithinStack in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Router.php:657
#22 Illuminate\Routing\Router:runRoute in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Router.php:623
#21 Illuminate\Routing\Router:dispatchToRoute in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Router.php:612
#20 Illuminate\Routing\Router:dispatch in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:176
#19 Illuminate\Foundation\Http\Kernel:Illuminate\Foundation\Http{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
#18 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/html/test-project/vendor/fideloper/proxy/src/TrustProxies.php:57
#17 Fideloper\Proxy\TrustProxies:handle in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#16 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#15 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21
#14 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#13 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#12 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21
#11 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#10 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#9 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27
#8 Illuminate\Foundation\Http\Middleware\ValidatePostSize:handle in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#7 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#6 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:62
#5 Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode:handle in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
#4 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#3 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:104
#2 Illuminate\Pipeline\Pipeline:then in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:151
#1 Illuminate\Foundation\Http\Kernel:sendRequestThroughRouter in /var/www/html/test-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:116
#0 Illuminate\Foundation\Http\Kernel:handle in /var/www/html/test-project/public/index.php:55`

Question: How could i perform a parallel (multi-threaded/multi-processing) copy?

New to Laravel and gcs here. I am performing a copy operation from a gcs directory to another gcs directory with a few images inside, however it takes around 8-10 secs for the process to complete:

 foreach` ($files as $file) {
     $targetFile = $target.substr($file, strpos($file, '/'));
     Storage::disk(self::Disk())->copy($file, $targetFile);
 `}

I know that gsutil has the -m command to copy multiple files like so:

gsutil -m cp -r dir gs://my-bucket
Is there a way i could do something similar(multi-process) in Laravel?

Driver is not Supported

Greetings. I am attempting to install this on Laravel 5.5.24 and getting an error when I try to call

$disk = Storage::disk('gcs');

The error I am getting is "Driver[] is not supported"

UPDATE: Just had to do a publish:vendor, I forgot to do that.

getClient() undefined.

Stack:
PHP7.2
Laravel 5.5

Error:
Call to undefined method Superbalist\Flysystem\GoogleStorage\GoogleStorageAdapter::getClient() at /application/app/Providers/FacadeServiceProvider.php:32

Install following the readme.md docs and when i'll use grab this error.

Using like:

\StorageClient::putObject("SOME INFO HERE");

'StorageClient' is a facade \App\Facades\StorageClient::class

Could you help me plz?

regards,

Set contentEncoding when uploading a file

I can't find anything in this repo or Superbalist/flysystem-google-cloud-storage about this issue.
When I try to upload a file with the following code, i cannot set the content-encoding to gzip

\Storage::disk('gcs')
    ->getDriver()
    ->put('myfile.json', gzencode($json, 8), [
        'metadata' => [
            'contentType'     => 'text/plain',
            'ContentEncoding' => 'gzip'
        ]
    ]);

I have tried with ContentEncoding and Content-Encoding inside and outside the metadata array.
The content-type is set correctly but the encoding is not.

Thanks in advance

How to get gs: URI

I need to make Google vision read the uploaded images into Google storage, and for that, I need to get the URI for the image, so to get it?

Thanks,

Custom Domain Url not returned correctly

My bucket name is a custom domain static.domain.com which point to directly to my bucket.

Setting GOOGLE_CLOUD_STORAGE_API_URI=null, $disk->url('my_file.ext'); returns correctly with https://storage.googleapis.com/static.domain.com/my_file.ext

When this is set GOOGLE_CLOUD_STORAGE_API_URI=http://static.domain.com, it returns http://static.domain.com/static.domain.com/my_file.ext which is not valid instead of http://static.domain.com/my_file.ext.

Any fix?

Accept metadata in options

Hello there,
The getOptionsFromConfig method should accept the metadata key as a possible value.

I require this for the following properties:

  • "contentType": string
  • "contentLanguage": string
  • "cacheControl": string

The official google cloud documentation shows that the StorageObject allows the metadata property.
https://googlecloudplatform.github.io/google-cloud-php/#/docs/v0.20.1/storage/storageobject?method=update

And the JSON API docs shows what properties the StorageObject can contain.
https://cloud.google.com/storage/docs/json_api/v1/objects#resource

Using JSON credentials not working.

Hi,

When I implement the cloud storage using my json credentials it does a oAuth check and fails. Could you please help clarify how to do this so that it validates my account properly..

Here is the laravel response:
BadRequestException in RequestWrapper.php line 283: Client error: POST https://www.googleapis.com/oauth2/v4/token` resulted in a 400 Bad Request response:
{
"error": "invalid_grant",
"error_description": "Invalid JWT: Token must be a short-lived token and in a reasonable t (truncated...)`

and here is the GCS driver setup in the filesystem

'gcs' => [ 'driver' => 'gcs', 'project_id' => env('GOOGLE_CLOUD_PROJECT_ID'), 'key_file' => storage_path(env('GOOGLE_CLOUD_KEY_FILE')), 'bucket' => env('GOOGLE_CLOUD_STORAGE_BUCKET'), 'path_prefix' => env('GOOGLE_CLOUD_STORAGE_PATH_PREFIX', null), 'storage_api_uri' => env('GOOGLE_CLOUD_STORAGE_API_URI', null), ],

Any help would be great...

Method getUrl is not working

Just stumbled upon this error:

I can correctly upload files (i found it in the firebase storage console) but when invoking the getUrl method here it is what I see:

BadMethodCallException in PluggableTrait.php line 85:
Call to undefined method League\Flysystem\Filesystem::getUrl

This is the simple code I'm using in a controller

$disk = Storage::disk('gcs');
$url = $disk->getUrl('media/test.png');

it seems the $disk doesn't have the getUrl Method.
I made a test in the GoogleCloudStorageServiceProvider.php file and here:

$adapter = new GoogleStorageAdapter($storageClient, $bucket, $pathPrefix, $storageApiUri);          
return new Filesystem($adapter);

the $adapter has the getUrl method, but the constructor new Filesystem($adapter) returns an object without that method.

Am I missing something?

putFilAs gives invalid_grant - Invalid JWT Signature

Hi,

First of all thank you for this package. I have been using it for the past couple of months and it has been working properly. The way I have set up the authentication is by add the json file in my storage and referencing it inside the filesystem.php. This is has been working, but since I left the part of uploading images to the cloud for quite a bit of time and now I am testing it again, it gives me the following error whenever I try to save an image.

message
:
"{↵ "error": "invalid_grant",↵ "error_description": "Invalid JWT Signature."↵}↵"
status_code
:
500

I tried to update to the latest version 2.0 hoping that will fix it, but it didn't help. If I dd(Storage::('gcs')) I can actually see the authentication data is actually being passed through. Any idea on what might be the problem? If you need more information, please let me know.

Failed to install

Hello, I tried installing your package, however installation failed and I received the following message. I am using a fresh installation of Laravel 5.3. If any more information is needed/wanted about this, please let me know. :)

Using version ^1.0 for superbalist/laravel-google-cloud-storage
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for superbalist/laravel-google-cloud-storage ^1.0 -> satisfiable by superbalist/laravel-google-cloud-storage[1.0.0].
    - superbalist/laravel-google-cloud-storage 1.0.0 requires superbalist/flysystem-google-storage ^3.0 -> satisfiable by superbalist/flysystem-google-storage[3.0.0, 3.0.1, 3.0.2, 3.0.3].
    - superbalist/flysystem-google-storage 3.0.0 requires google/cloud ^0.8.0 -> satisfiable by google/cloud[v0.8.0].
    - superbalist/flysystem-google-storage 3.0.1 requires google/cloud ^0.8.0 -> satisfiable by google/cloud[v0.8.0].
    - superbalist/flysystem-google-storage 3.0.2 requires google/cloud ^0.8.0|^0.9.0 -> satisfiable by google/cloud[v0.8.0, v0.9.0].
    - superbalist/flysystem-google-storage 3.0.3 requires google/cloud ^0.8.0|^0.9.0 -> satisfiable by google/cloud[v0.8.0, v0.9.0].
    - google/cloud v0.8.0 requires google/auth 0.10 -> satisfiable by google/auth[v0.10].
    - google/cloud v0.9.0 requires google/auth 0.10 -> satisfiable by google/auth[v0.10].
    - Conclusion: don't install google/auth v0.10

delete doesn't work

I try to delete a file like this:

$exist = Storage::disk('gcs')->exists($path);

        if($exist) {
            Storage::disk('gsc')->delete($path);
        }

but I get this error:

"Driver [] is not supported

the rest of the methods work less delete

compatibility with Superbalist/flysystem-google-cloud-storage:6.0

laravel-google-cloud-storage
requires flysystem-google-cloud-storage:5.0
requires google/cloud:0.35

but flysystem-google-cloud-storage:6.0
requires google/cloud:>=0.21 <0.50

will laravel-google-cloud-storage update to requires flysystem-google-cloud-storage:6.0

error:

composer require google/cloud

Using version ^0.53.0 for google/cloud                                                                              
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)                                                                       
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - superbalist/flysystem-google-storage 5.0.3 requires google/cloud ^0.10.2|^0.11.0|^0.12.0|^0.13.0|^0.21.0|^0.22.0|^0.23.0|^0.24.0|^0.25.0|^0.26.0|^0.27.0|^0.28.0|^0.29.0|^0.30.0|^0.31.0|^0.32.0|^0.33.0|^0.34.0|^0.35.0 -> satisfiable by google/cloud[v0.10.2, v0.11.0, v0.11.1, v0.12.0, v0.13.0, v0.13.1, v0.13.2, v0.21.0, v0.21.1, v0.22.0, v0.23.0, v0.24.0, v0.25.0, v0.25.1, v0.26.0, v0.27.0, v0.28.0, v0.29.0, v0.30.0, v0.30.1, v0.31.0, v0.31.1, v0.32.0, v0.32.1, v0.33.0, v0.33.1, v0.34.0, v0.34.1, v0.35.0] but these conflict with your requirements or minimum-stability.

Caller does not have access

I am getting the following response error - it appears I have given correct role access to the API client in google

{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Caller does not have storage.objects.get access to object your-bucket/test.txt."
}

Given keyfile path /*/ does not exist

I include in my app.yaml file the variable:
GOOGLE_CLOUD_KEY_FILE: "/home/nameuser/projectFile/key.json"
equivalent to the path within App Engine, however the following error appears:

Given keyfile path /home/nameuser/projectFile/key.json does not exist

I do not know if I did something wrong.

Implement temporaryUrl method

It was mentioned previously (#35), but now the official adapters like S3 and Rackspace have the capabilities built-in as:

\Illuminate\Filesystem\FilesystemAdapter::temporaryUrl

public function temporaryUrl($path, $expiration, array $options = [])
    {
        $adapter = $this->driver->getAdapter();

        if ($adapter instanceof CachedAdapter) {
            $adapter = $adapter->getAdapter();
        }

        if (method_exists($adapter, 'getTemporaryUrl')) {
            return $adapter->getTemporaryUrl($path, $expiration, $options);
        } elseif ($adapter instanceof AwsS3Adapter) {
            return $this->getAwsTemporaryUrl($adapter, $path, $expiration, $options);
        } elseif ($adapter instanceof RackspaceAdapter) {
            return $this->getRackspaceTemporaryUrl($adapter, $path, $expiration, $options);
        } else {
            throw new RuntimeException('This driver does not support creating temporary URLs.');
        }
    }

It should be possible to implement this in the adapter for GCS.

Can't set contentType when storing file

Hello, I'm using your GCS driver with my laravel project and I'm attempting to store a file publicly but also set the contentType I've researched and found that I can pass an array metadata with options that should be passed along to GCS but it appears as I'm doing something wrong.

$file->storePubliclyAs($path, $filename = Str::random(40).'.'.$file->guessExtension(), [
    'disk' => app()->environment('local') ? 'local' : 'gcs',
    'metadata' => ['contentType' => $file->getMimeType()],
]);

I've also verified that $file->getMimeType() is text/vcard but always ends up as application/octet-stream in GCS bucket.

I've also tried every variation of contentType Content-Type mimeType mimetype etc inside and outside of metadata array and am at a loss.

Any help would be greatly appreciated!

Package Should Publish its Service File

It would be great if this package could publish it's service files. This way we could configure the client with specific configurations we might want to use.

Deploying to Google Cloud App Engine

Hello,
I'm deploying my app to GC AE but I got this message :

PHP Notice: Google\Cloud\Core\Exception\GoogleException: Given keyfile path None does not exist in /app/vendor/google/cloud-core/src/ClientTrait.php:133 Stack trace: #0 /app/vendor/google/cloud-core/src/ClientTrait.php(99):

I didn't put any key_file env variable as in authentification point 4 it says :
If running in Google App Engine, the built-in service account associated with the application will be used.

In local everything works perfectly, I use the feature from authentification point 3 (with application_default_credentials.json).

Here is my env vars used in local and on GC AE
GOOGLE_CLOUD_PROJECT_ID: "my-app-id" GOOGLE_CLOUD_STORAGE_BUCKET: "my-app-bucket"

error on last update google cloud

{ "error": { "errors": [ { "domain": "global", "reason": "required", "message": "Bucket is requester pays bucket but no user project provided." } ], "code": 400, "message": "Bucket is requester pays bucket but no user project provided." } }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.