首页 文章

上传时的Google Cloud 存储错误

提问于
浏览
-1
# 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');

上传时出现以下错误:

致命错误:未捕获Google \ Cloud \ Core \ Exception \ NotFoundException:{“error”:{“errors”:[{“domain”:“global”,“reason”:“notFound”,“message”:“Not Found” /} / google/vendor/google/cloud-core/RequestWrapper.php:257堆栈跟踪:#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(资源ID#46)#4 {main在第257行的/www/google/vendor/google/cloud-core/RequestWrapper.php中投放

1 回答

  • 0

    应该这样做 if projectid / bucket /文件都存在:

    use Google\Cloud\Storage\StorageClient;
    $storage = new StorageClient([
        'projectId' => 'YourProjectId'
    ]);
    
    $bucket = $storage->bucket('mybucker');
    $bucket->upload(
        fopen('/test.txt', 'r')
    );
    

相关问题