我在我的 Laravel 项目中使用来自 github 的laravel-google-cloud-storage包将文件上传到谷歌云存储。我的文件中有一个 JSON 文件,其中包含凭据、项目 ID 和存储桶列表.env
。
.env 文件
GOOGLE_CLOUD_PROJECT_ID='myproject-123456'
GOOGLE_CLOUD_KEY_FILE=/var/www/project/credintials.json
GOOGLE_CLOUD_STORAGE_BUCKET=minisite_event
.json 凭据
{
"type": "service_account",
"project_id": "myproject-123456",
"private_key_id": "MY_PROJECT_KEY_ID",
"private_key": "-----BEGIN PRIVATE KEY-----\nTHEWHOLEKEYHEREWITHVERYVERYLONGTEXTLIKEANYOTHERPRIVATEKEYFILE=\n-----END PRIVATE KEY-----\n",
"client_email": "TEST@PROJECT_ID.iam.gserviceaccount.com",
"client_id": "99112211221122112211",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/ATESTSTRING.iam.gserviceaccount.com"
}
文件系统配置
'gcs' => [
'driver' => 'gcs',
'project_id' => env('GOOGLE_CLOUD_PROJECT_ID', 'your-project-id'),
'key_file' => env('GOOGLE_CLOUD_KEY_FILE', null), // optional: /path/to/service-account.json
'bucket' => env('GOOGLE_CLOUD_STORAGE_BUCKET', 'your-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
]
在我的 Laravel 中,我试图将文件放入文件系统
$disk = Storage::disk('gcs');
$path = $disk->putFile('event_'.$id, $request->file('qqfile'));
然后我得到这个错误:
NotFoundException
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found"
}
],
"code": 404,
"message": "Not Found"
}
}
我不确定我做错了什么。此外,该软件包没有很好的文档记录,这是我能找到的已经实现 Filesystem 的最佳软件包。