简体   繁体   English

使用 laravel 将图像上传到 Firestore

[英]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.

相关问题 Flutter:使用 ImagePickerWeb 将图片上传到 Firestore - Flutter: Upload image to Firestore using ImagePickerWeb 如何使用 crud 方法将图像文件上传到 FIRESTORE? - How to upload image files to FIRESTORE using crud method? 使用 React 将图像上传到 firestore - upload images to firestore using react 如何上传图像 Url 上传到 Fire Storage 并同时将其保存在 fireStore 使用 Java - how to upload image Url Uploaded to Fire Storage and Save it in fireStore at the Same time Using Java 如何将图片正确上传到 Firebase 存储并保存到 firestore 的链接 - How to properly upload image to Firebase Storage and save link to firestore 如何使用 Laravel 删除 Firestore 上的数组元素 - How to delete element of an array on Firestore using Laravel 使用 React 将图像上传到 Firebase/Firestore v9 中的现有文档 - Upload Image to Existing doc in Firebase/Firestore v9 with React Laravel Firebase 图片上传分配 URL - Laravel Firebase image upload assign URL Flutter-Firestore:- 无法将图像上传到 Firestore。 它说找不到参考 object - Flutter-Firestore:- Unable to upload image to firestore. its says reference object is not found 我想使用 flutter 在云 Firestore 上上传 excel 文件 - I want to upload excel file on cloud firestore using flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM