简体   繁体   English

Firestore Cloud Function - 如何从 url 读取参数

[英]Firestore Cloud Function - How to read params from url

I need to extract the params from http url in firestore cloud function,我需要从 firestore 云 function 中的 http url 中提取参数,
HTTP URL HTTP URL

 https://us-central-xxxxxxxxxxx.cloudfunctions.net/somefunction?name=ABC&age=80

Firestore Cloud function Firestore 云 function

export const somefunction = functions.https.onRequest(async (request, response) => {
  var name = // need to extract name from request
  var age = // similarly need to extract age from request
}

Can anyone help me out with this?谁能帮我解决这个问题?

You can use the request object to access the query parameters similar to what you do in Express Js您可以使用request object 来访问类似于您在Express Js中所做的查询参数

export const somefunction = functions.https.onRequest(async (request, response) => {
  var name = request.query.name
  var age = request.query.age
}

If the request was from a POST request then you can use request.body.* for accessing values.如果请求来自POST请求,那么您可以使用request.body.*来访问值。

I have a similar issue where I cannot get req.url and req.query.abc as asked in Cannot get req.path and req.query.abc with firebase functions我有一个类似的问题,我无法获得req.urlreq.query.abc ,如Cannot get req.path and req.query.abc with firebase functions 中所述

As mentioned in the comments of Call Firebase cloud function via GET and return parameters this is happening only on development.正如通过 GET 调用 Firebase 云 function 并返回参数的评论中提到的,这仅发生在开发中。

After searching for a long time I came across this article https://howtofirebase.com/cloud-functions-migrating-to-node-8-9640731a8acc where it said firebase-tools have to be of 4.0.0 version.搜索了很长时间后,我发现了这篇文章https://howtofirebase.com/cloud-functions-migrating-to-node-8-9640731a8acc ,其中说 firebase firebase-tools必须是 4.0.0 版本。 I've updated my firebase-tools to 4.0.0 and I can get the query parameters normally我已经将我的firebase-tools更新到4.0.0,我可以正常获取查询参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Firebase 云从 Cloud Firestore 读取数据 function - Read data from Cloud firestore with Firebase cloud function 使用 firebase 云 function 从云 Firestore 读取数据? - Read data from cloud firestore with firebase cloud function? 如何使用 firebase function 从云 Firestore 读取数据并循环并将其推送到列表 - How to read data from cloud firestore with firebase function and loop and push it to list 如何使用从 FIrestore 读取的数据创建云 Function REST API 端点 - How to create Cloud Function REST API endpoints with the read data from FIrestore 如何从 Firebase Cloud Function 访问 firestore.Timestamp - How to access firestore.Timestamp from Firebase Cloud Function 将数据从 Google Cloud 保存到 Firestore Function - Saving data to Firestore from Google Cloud Function 使用 URL 参数查询 Firestore 数据库 - Querying Firestore database with URL params 如何在云 function 或 nodejs 中转换 Firestore 时间戳 - How to convert firestore TimeStamp in cloud function or nodejs 如何从 firebase 存储中获取图像 URL 列表并将其上传到云 firestore? - How to get a list of image URL from firebase storage and upload it to cloud firestore? Cloud Function 无法解析 JSON 并从 Webhook 写入 Cloud Firestore - Cloud Function failing to parse JSON and write to Cloud Firestore from Webhook
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM