laravel-google-cloud-storage
laravel-google-cloud-storage copied to clipboard
(ServiceException) json key is missing the type field
I updated to latest version 2.2.1 and get that if i upload image to bucket.
Could you please provide a full stack trace, and the contents of your config file?
Could you please provide a full stack trace, and the contents of your config file?
I use Google App Engine
Use config in filesystem laravel :
'gcs' => [ 'driver' => 'gcs', 'project_id' => env('GOOGLE_CLOUD_PROJECT_ID'), 'key_file' => env('GOOGLE_CLOUD_KEY_FILE', null), // optional: /path/to/service-account.json 'bucket' => env('GOOGLE_CLOUD_STORAGE_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 ],
Before update my code work successfull.
The PR in question doesn't actually make any logical changes, it just changes the order of operations, so I cant see how this fixes your issue..
Please can you provide:
1: The full stack trace for the ServiceException
2: The value of env('GOOGLE_CLOUD_KEY_FILE', null)
The only way I can see this working is if env('GOOGLE_CLOUD_KEY_FILE', null) === null
The PR in question doesn't actually make any logical changes, it just changes the order of operations, so I cant see how this fixes your issue..
Please can you provide: 1: The full stack trace for the
ServiceException
2: The value ofenv('GOOGLE_CLOUD_KEY_FILE', null)
The only way I can see this working is if
env('GOOGLE_CLOUD_KEY_FILE', null) === null
Its same with my logic bro. If you learn clean code dont use === null in if argument
i get same issue, basically my laravel project running on google app yesterday still working fine without use GOOGLE_CLOUD_KEY_FILE but now i get this error.

Can you please update your config and replace
'project_id' => env('GOOGLE_CLOUD_PROJECT_ID')
with
'project_id' => env('GOOGLE_CLOUD_PROJECT')
and let me know if it works for you then
i still get same error bro, and how if i use the json key for my google app engine, because i try put my directory of json key in my locahost project and it's work but if i deploy to app engine still get this issue, thanks for your help.

Can you tell me if env('GOOGLE_CLOUD_KEY_FILE', null)
is null or whether it has an actual (string etc.) value in your situation? I want to merge your PR but I need to know it will not break for others, and since I can't replicate your situation it is very difficult to do so. Thanks
i have solve it with this step :
- make json api key from here https://console.cloud.google.com/apis/credentials/serviceaccountkey
- download and put file to storage folder of your project
- edit your key_file variable to
storage_path('file_name.json')
like picture bellow

@alfin87aa @ralfiannor Are you satisfied with this solution or do you need it to be able to work with a null
key_file
?
@nicja @MaggotMouth for me it's enough, thanks for your help 👍
Can you tell me if
env('GOOGLE_CLOUD_KEY_FILE', null)
is null or whether it has an actual (string etc.) value in your situation? I want to merge your PR but I need to know it will not break for others, and since I can't replicate your situation it is very difficult to do so. Thanks
Work perfect if i edit your code to handle null. Please, merge my pull request https://github.com/Superbalist/laravel-google-cloud-storage/pull/61 and this issue will solve.
i have solve it with this step :
- make json api key from here https://console.cloud.google.com/apis/credentials/serviceaccountkey
- download and put file to storage folder of your project
- edit your key_file variable to
storage_path('file_name.json')
like picture bellow![]()
Add google credential file in your source project is bad. Dont try it in production.
i have solve it with this step :
- make json api key from here https://console.cloud.google.com/apis/credentials/serviceaccountkey
- download and put file to storage folder of your project
- edit your key_file variable to
storage_path('file_name.json')
like picture bellow![]()
Add google credential file in your source project is bad. Dont try it in production.
You don't need to put it in your storage folder.
You can just deploy the key with your app to App Engine, then set the key_file
to that file (outside of storage); or alternatively, don't set a key_file
at all and just set the GOOGLE_APPLICATION_CREDENTIALS
env var.
@nicja this issue has wreaked havoc on us today. We need the ability to set 'key_file' => null
as per the proposed PR.
I don't actually see why we need to do any array_merge
at all though, since the project ID is already in the service key? Commented on that in the PR.
@nicja @ralfiannor I rewrote the entire function so it makes more sense logically, it's also commented so you can easily tell what's going on. In my PR I wrote up the issue.
I've got a same issue on standard app engine. It doesn't work with GOOGLE_CLOUD_KEY_FILE set to null. As I can recall, it used to work on v2.1.0, but it has "json key is missing the type field" error now.
I encountered the same issue today, i see a pull request is awaiting. Can anyone check / approve this?
Hi all, apologies for how long this has been outstanding. Unfortunately I can't test the specific scenarios that are broken. We now have 2 open PRs to fix this issue. I am in favour of #61 as it includes updates to the README. @cjcox17 @EntonoX @ralfiannor @ShaMSofT can you let me know if this PR solves the issue for you? Thanks!
EDIT: #63 is preferred, not #61
@nicja I'm testing #63 right now, I can test #61 as well if this is a preferred PR. i'll report back today.
@EntonoX thank you! Apologies, I meant #63 which has the changes to the README
@nicja I tested #63 locally and within GCS docker container. I was not able to get it working without using the service account key as a secret. (So i needed to provide the 'key_file_path' environment variable). Without this environment variable i got a 'insufficient permission' error.
I can not judge if this is a service account rights setting or some other problem. Maybe you or @cjcox17 can provide some details for this?
🙏
I'm able to replicate this in GKE.
I'm not using a key file. I just want the lib to use the default service account of the instance, which the CredentialsLoader
does as fallback.
I was able to hack around it by setting key_file
in the config to an empty string. This passes the if (is_string($keyFile)) {
check in createClient
and tries to load the client with just a project id and empty keyFilePath. In Google's ClientTrait
, it fails their loose if ($config['keyFile']) {
check and lands up using return CredentialsLoader::fromEnv() ?: CredentialsLoader::fromWellKnownFile();
which is what I want.
I'm using #63 in production without a key_file, I'll setup another instance this weekend to test.
@EntonoX @matthewgoslett Can you provide your filesystem.php config for the GCS disk? I'll use this when I'm testing.
Set up the newest version of this today on a new App Engine instance and ran into the same issue.
I was able to hack around it by setting key_file in the config to an empty string. This passes the if (is_string($keyFile)) { check in createClient and tries to load the client with just a project id and empty keyFilePath. In Google's ClientTrait, it fails their loose if ($config['keyFile']) { check and lands up using return CredentialsLoader::fromEnv() ?: CredentialsLoader::fromWellKnownFile(); which is what I want.
This solution worked for me, thank you @matthewgoslett
@matthewgoslett @bredmor You are experiencing the ongoing issue that the pending pull request fixes. Pull request #63 Works in these cases.
@ EntonoX @nicja I setup another Google Cloud Compute Engine Instance yesterday and verified the the pull request works as intended.
@EntonoX Verify that you're using the newest config file included in the pull request and verify that your instance has the proper permissions on the service account. For testing I simply select "Allow full access to all API's". The README has been updated as well.
Can you post your Laravel config, docker config, and a stack trace?
@nicja If there is a separate issue for Docker, Kubernetes, or Google Cloud App Engine, I think it would make sense to approve the current pull request to fix the current issue and address the other issue separately so people like @matthewgoslett and @bredmor and myself don't continue to run into this issue.
@nicja @ralfiannor I rewrote the entire function so it makes more sense logically, it's also commented so you can easily tell what's going on. In my PR I wrote up the issue.
it's ok bro.
I was deploying on GAE flexible environment and i got that error too, my config is like this:
'key_file' => env('GOOGLE_CLOUD_KEY_FILE', null), // optional: /path/to/service-account.json
Has been found a solution?
I was deploying on GAE flexible environment and i got that error too, my config is like this:
'key_file' => env('GOOGLE_CLOUD_KEY_FILE', null), // optional: /path/to/service-account.json
Has been found a solution?
Downgrade version until fix version release.
Hi found the solution... set : 'key_file' => env('GOOGLE_CLOUD_KEY_FILE', '') // empty string instead null solve for me the problem