Q: Google Cloud Storage Error on Upload # Includes the autoloader for libraries installed with composer
require __DIR__ . '/vendor/autoload.php';

# Imports the Google Cloud client library
use Google\Cloud\Storage\StorageClient;

# Your Google Cloud Platform project ID
$projectId = 'projectId ';

$storage = new StorageClient([
    'projectId' => $projectId,
    'keyFilePath' =>'./key.json'
]);

$bucket = $storage->bucket('mybucker');

// Upload a file to the bucket.
$file = fopen('./test.txt', 'r');

I got the following error on upload:

Fatal error: Uncaught Google\Cloud\Core\Exception\NotFoundException: { "error": { "errors": [ { "domain": "global", "reason": "notFound", "message": "Not Found" } ], "code": 404, "message": "Not Found" } } in /www/google/vendor/google/cloud-core/RequestWrapper.php:257 Stack trace: #0 /www/google/vendor/google/cloud-core/RequestWrapper.php(162): Google\Cloud\Core\RequestWrapper->convertToGoogleException(Object(GuzzleHttp\Exception\ClientException)) #1 /www/google/vendor/google/cloud-core/Upload/MultipartUploader.php(64): Google\Cloud\Core\RequestWrapper->send(Object(GuzzleHttp\Psr7\Request), Array) #2 /www/google/vendor/google/cloud-storage/Bucket.php(268): Google\Cloud\Core\Upload\MultipartUploader->upload() #3 /www/google/index.php(20): Google\Cloud\Storage\Bucket->upload(Resource id #46) #4 {main} thrown in /www/google/vendor/google/cloud-core/RequestWrapper.php on line 257


A: That should do it if the projectid/bucket/file all exists:
use Google\Cloud\Storage\StorageClient;
$storage = new StorageClient([
    'projectId' => 'YourProjectId'
]);

$bucket = $storage->bucket('mybucker');
$bucket->upload(
    fopen('/test.txt', 'r')
);

