Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

supplied key param cannot be coerced into a private key #103

Open
AmG2000 opened this issue Oct 29, 2020 · 7 comments
Open

supplied key param cannot be coerced into a private key #103

AmG2000 opened this issue Oct 29, 2020 · 7 comments

Comments

@AmG2000
Copy link

AmG2000 commented Oct 29, 2020

My config

'gcs' => [
          'driver' => 'gcs',
          'project_id' => env('GOOGLE_CLOUD_PROJECT_ID', 'your-project-id'),
          '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'),
           ], // 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
          'visibility' => 'public', // optional: public|private
],

When I try storing a file using Storage:disk('gcs')->putFile('folder', $request->file('example_file')) I get the error "Supplied key param cannot be coerced into private key. Does anyone know how to get around this? I'm on laravel 7.22.2

@Jakatut
Copy link

Jakatut commented Dec 8, 2020

Hey,

Any chance you've found a resolution to this? I've run into the same issue.

@AmG2000
Copy link
Author

AmG2000 commented Dec 9, 2020

I realized the issue only occured when I stored the key in an environment variable, as opposed to just referencing the json file. So I just referenced the json file instead of supplying an array of its values

@Jakatut
Copy link

Jakatut commented Dec 9, 2020

Ah I see. I ended up using the private key still, but it turns out Laravel escaped the new lines it read. I just replaced these escaped lines with new lines after reading the env.

Thanks for the reply :)

@AmG2000
Copy link
Author

AmG2000 commented Dec 9, 2020

I just replaced these escaped lines with new lines after reading the env

How'd you do this?

@Jakatut
Copy link

Jakatut commented Dec 9, 2020

like this: str_replace('\n', "\n", env('GOOGLE_CLOUD_PRIVATE_KEY')),

Make sure your private key is wrapped in quotes in the .env file too.

@AmG2000
Copy link
Author

AmG2000 commented Dec 9, 2020

Right. Your solution's much more elegant than mine. Thankyou

@st-man-hori
Copy link

I had the same problem.
but this issue solved it.
Thanks!

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

No branches or pull requests

3 participants