6

I've been clattering around the google developers console for a while, and i just can't get it to work with Craft! I figured it'd be simple (and it may well be!) considering in Craft it just asks for two bits of data, "Access Key ID" and "Secret Access Key".

After an age of digging about in the google developes console site and a bit of searching, i ended up in the Project Dashboard for my Cloud Storage. Enabling "Interoperable Access" gave me some new tabs on the side, one of which is "Interoperable Access", and in there FINALLY i found two strings that have the names "Access Key" and "Secret".

Putting them into Craft and hitting refresh next to Bucket gives me the error "Credentials rejected by target host".

And so now i'm stumped! Does anyone have experience using Google Cloud Storage with Craft who can point me in the right direction?

  • Probably best to reproduce this error and then send us a support ticket using the dashboard widget and including the log files. – Andris Sevcenko Feb 9 '15 at 12:57
  • Thanks Andris! Really fast and awesome support :) For anyone else having this kind of problem... As it turns out, the initial issue was my server time not being set as Google Cloud wanted. I'm in the UK and using a server in Germany. I set it so the time synched with time1.google.com and that fixed my first issue. Another problem popped up after that (unknown error!) but Craft support got in there and patched the issue for me so i'm good to go (and hopefully others in future wont have that problem! Sweet!) – Dan Owen Feb 11 '15 at 15:36
  • 1
    @DanOwen Please post your solution as an answer below and accept it as the correct answer by clicking on the checkbox. You might have to wait 24hrs before you can accept it so just remember to come back to do that. – Anna_MediaGirl Feb 20 '15 at 0:55
3

Craft 3:

Once you have created your project in GC, navigate to GC Storage.

  1. Create a bucket. You can only create a bucket containing the domain name if you are able to prove ownership. For example, I (personally) could not create files.craftcms.com as my bucket. Otherwise it can be anything you'd like. Or check out the Bucket and Object Naming Guidelines

  2. Navigate to IAM & admin. We'll need to create a Service Account that can be used to give Craft access to the bucket.

  3. Give your Service account a name. For example, "Cloud Storage". Google will create a service account ID that will look something like cloud-storage@<project-name>.iam.gserviceaccount.com. For Project Role, (you can filter) but choose "Storage Admin". You'll also want to select the checkbox labeled, "Furnish a new private key". Choose json as the format and click "Save".

  4. A file will be downloaded to your computer - awesome. Next install the Google Cloud Plugin for Craft: composer require craftcms/google-cloud

  5. Once installed, create a new Asset Resource and instead of "Local" choose "Google Cloud Storage" as a volume type.

  6. Give your resource a name. For example, "Images". If you choose to have public url's use this url: http://storage.googleapis.com/. Unless you have a specific DNS record set up to serve images from that you want to use, you could do that too. Enter the project ID of your project. You can find that by clicking on your project name - very top (blue) nav bar. For example, it could be my-project

  7. Finally, remember that .json file that was downloaded? Open that with your favorite text editor and paste the contents into "Contents of the access key file". Hit the "Refresh" button, and you should now see the name of your primary bucket. In my case files.mysite.com. You might also notice that Craft will update the base url to the files: http://storage.googleapis.com/files.mysite.com/

From there, you could create sub-folders in GCS. In my case, I've created one called images. I will update that in the Subfolder input: images.

Save your newly created resource!

  • Great walkthough. I then received errors that the Cloud Storage Console API needed allowing for the project. I sorted that, then had to add credentials for it. The private_key_id proved to be the same as the one in the JSON. – Clive Portman Nov 26 '18 at 15:17
  • 1
    And even after this, the images weren't showing publicly. This sorted it: Making groups of objects publicly readable section on cloud.google.com/storage/docs/access-control/making-data-public – Clive Portman Dec 6 '18 at 12:06
1

As it turns out, the initial issue was my server time not being set as Google Cloud wanted. I'm in the UK and using a server in Germany. I set it so the time synched with time1.google.com and that fixed my first issue.

Another problem popped up after that (unknown error!) but Craft support got in there and patched the issue for me so i'm good to go (and hopefully others in future wont have that problem! Sweet!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.