[英]Upload image to firestore using laravel
I am trying to upload an image to firestore storage via using Laravel and i am getting an error:我正在尝试通过使用 Laravel 将图像上传到 Firestore 存储,但出现错误:
This is my code:这是我的代码:
$bucketName = 'my-bucket';
$objectName = $request->file('banner'); //Image
$source = $request->file('banner')->move(public_path('/public/firebase-temp-uploads'));
//return dd($source);
$storage = new StorageClient();
$file = fopen($source, 'r');
$bucket = $storage->bucket($bucketName);
$object = $bucket->upload($file, [
'name' => $objectName
]);
printf('Uploaded %s to gs://%s/%s' . PHP_EOL, basename($source), $bucketName, $objectName);
I have followed the documentation and still getting this error:我已按照文档进行操作,但仍然出现此错误:
{ "error": { "code": 401, "message": "Invalid Credentials", "errors": [ { "message": "Invalid Credentials", "domain": "global", "reason": "authError", "locationType": "header", "location": "Authorization" } ] } } { "error": { "code": 401, "message": "Invalid Credentials", "errors": [ { "message": "Invalid Credentials", "domain": "global", "reason": "authError ", "locationType": "header", "location": "授权" } ] } }
Thanks in advance提前致谢
As mentioned by KgosiE, the error was due to the wrong reference of the JSON file for credentials and it is resolved now.正如 KgosiE 所提到的,该错误是由于 JSON 文件的凭据引用错误,现在已解决。 Anyone experiencing this issue first try to check config/filesystems.php if you have the correct credentials set or not as said by Mátyás Grőger.遇到此问题的任何人首先尝试检查 config/filesystems.php 是否设置了正确的凭据,如 Mátyás Grőger 所说。
For more information, you can refer to the Article and video on How to upload an image to Firebase Storage from Laravel PHP project and the Public Documentation on how to upload files with cloud storage on the web. For more information, you can refer to the Article and video on How to upload an image to Firebase Storage from Laravel PHP project and the Public Documentation on how to upload files with cloud storage on the web.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.