bash 使用 REST API 将文件上传到 Firebase 存储
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37631158/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uploading files to Firebase Storage using REST API
提问by cnic
Right now, the Firebase documentation guides you on uploading files to Firebase Storage by using their JavaScript library.
现在,Firebase 文档会指导您使用其 JavaScript 库将文件上传到 Firebase Storage。
I am operating a server without NodeJS installed. Is it possible to upload files like image, audio, through the Firebase REST API?
我正在运行没有安装 NodeJS 的服务器。是否可以通过 Firebase REST API 上传图像、音频等文件?
At the moment I am using curl in a bash script to send JSON. I would prefer not to store base64 encoding in a database field, I want the file to be stored in a folder inside the Storage section.
目前我在 bash 脚本中使用 curl 来发送 JSON。我不想将 base64 编码存储在数据库字段中,我希望将文件存储在 Storage 部分内的文件夹中。
Storage folder shown below:
存储文件夹如下图:
采纳答案by katfang
Firebase Storage uses Google Cloud Storage under the hood, so you can use the GCS REST API to get 90% of the way there. (Docs here.)
Firebase 存储在底层使用 Google Cloud Storage,因此您可以使用 GCS REST API 完成 90% 的工作。(文档在这里。)
There's a couple differences.
有一些区别。
- Download URLs won't be automatically generated until you access it through the Firebase Storage SDK.
- You won't be able to use Firebase Authentication to upload through the GCS REST endpoint. You'll either need to set up OAuth (which, you might be able to get through Google Sign in with Authentication) or a service account. (Here's an exampleof how you can authenticate from Node.js to GCS.)
- 在您通过 Firebase Storage SDK 访问之前,不会自动生成下载 URL。
- 您将无法使用 Firebase 身份验证通过 GCS REST 端点上传。您需要设置 OAuth(您可以通过 Google 身份验证登录)或服务帐户。(这是一个如何从 Node.js 到 GCS 进行身份验证的示例。)