Closed JulieVelghe closed 2 months ago
Context here: https://github.com/craftcms/cms/discussions/15284#discussioncomment-10137597
If you remove Craft/PHP from the equation and try to connect to Google Cloud storage using the same credentials in your D:/Julie/Repos/Ritcs/erasmushogeschool-brussel-fb3422db4ecf.json
file via the CLI, are you able to connect, upload, or delete files from the CLI in that scenario?
@angrybrad I haven't tried via the cli yet. I did try to remove Craft from the equation by making a simple php script that tries to upload a file using the same json credential file, and that seems to work.
the setup for this test was quite simple: And below the script I used:
<?php
require 'vendor/autoload.php';
use Google\Cloud\Storage\StorageClient;
// Authenticating with keyfile data.
$storageClient = new StorageClient([
'keyFilePath' => __DIR__ . '/data/erasmushogeschool-brussel-fb3422db4ecf.json',
]);
$bucket = $storageClient->bucket('ritcs-folio');
if ($bucket->exists()) {
echo 'Bucket exists!';
}else{
echo 'Bucket not found';
}
$buckets = $storageClient->buckets();
foreach ($buckets as $bucket) {
echo $bucket->name() . PHP_EOL;
}
// Upload a file to the bucket.
$sPath = __DIR__ . '/data/PaulineNeverSaidIWasAnAngel.mp3';
$objectName = "audio/PaulineNeverSaidIWasAnAngel.mp3";
$options = [
'name' => $objectName
];
try {
$bucket -> upload(
fopen($sPath, 'r'),
$options
);
echo "File was successfully uploaded/written to Google Cloud Storage.";
} catch (Exception $e) {
echo "Could not upload/write the file to Google Storage. Reason: {$e->getMessage()}";
}
?>
@angrybrad I've just tried to use the cli. I have been able to use the json key file and upload the audio file: What I did get however on the cli, when I first tried to list the projects, was an error telling me I needed to enable the Cloud Resource Manager api. Is this api also needed for the craft plugin? Or are there any other api's that perhaps need to be enabled?
@JulieVelghe this guide is a little old now but may help with permissions: https://gist.github.com/croxton/77c610289b631998283efa637f66b9f3
In particular note that bucket access must be set to fine-grained (per-object) NOT uniform (per bucket) to work properly with the Craft Google Cloud plugin.
@croxton yes, that fine-grained access did fix it.
Thanks, all - I've added more details to the setup instructions https://github.com/craftcms/google-cloud/commit/f4e29a2e993df2a88d94fe24c2942eb47578b893
Description
Hi all, we've made a website for a client, where we now need to be able to upload files to a google cloud storage via a form. My media system for audio files is setup like this: I am using variables from my env file:
GOOGLE_APPLICATION_CREDENTIALS="D:/Julie/Repos/Ritcs/erasmushogeschool-brussel-fb3422db4ecf.json" GOOGLE_CLOUD_PROJECT_ID="erasmushogeschool-brussel" GOOGLE_CLOUD_URL="https://storage.googleapis.com/ritcs-folio" When I submit my form with an audio file, I get a filesystem error (see attached pdf) Filesystem Error – craft_errors_FsException.pdf I've checked on Google Cloud, and our service account has the role 'Storage Admin', which should have enough rights to everything.
Steps to reproduce
Additional info