小编Unk*_*own的帖子

在nodejs中使用https.request发送表单数据

我正在尝试使用我的nodejs服务器将请求发布到另一台服务器,然后我必须将响应保存在文件中。我正在使用nodejs https.request 模块。

这是我的要求:

    var formData = new FormData();
    formData.append('first',3);
    formData.append('second', '25');
    formData.append('source_file', fs.createReadStream(sourcefile));
    formData.append('source_image', fs.createReadStream(sourceimage));

var options = {
    hostname: 'ip',
    path: '/api/path',
    method: 'POST'
}
var file = fs.createWriteStream("file.pdf");
var req = https.request(options, (response) => {
    response.pipe(file);
    console.log("File saved");
    response.send("done")
  });

  req.on('error', (e) => {
    console.error(e);
  });

  req.write(formData);
  req.end();
Run Code Online (Sandbox Code Playgroud)

但我收到错误

First argument must be a string or Buffer
Run Code Online (Sandbox Code Playgroud)

我尝试使用发送我的文件formData.toString(),但是使用它时,错误消失了,但我的文件无法正常工作,而且我也发送了如下数据:

 var formData = new FormData();
formData = {
        first: 3,
        second: '25',
        source_file: fs.createReadStream(sourcefile),
        source_image: fs.createReadStream(sourceimage)
    }; …
Run Code Online (Sandbox Code Playgroud)

javascript https node.js

7
推荐指数
2
解决办法
2万
查看次数

消息未在云功能中得到确认

我正在尝试将 google pubsub 与云功能一起使用,我所有的东西都运行良好,但我的消息没有得到确认

我做了这些事情:

1)创建主题

2)创建函数

3) 将函数的触发器设置为 google cloud pubsub

4)为pubsub选择主题

5)设置节点版本为8

这是我的默认云功能:

/**
 * Triggered from a message on a Cloud Pub/Sub topic.
 *
 * @param {!Object} event Event payload.
 * @param {!Object} context Metadata for the event.
 */
exports.helloPubSub = (event, context) => {
  const pubsubMessage = event.data;
  console.log(Buffer.from(pubsubMessage, 'base64').toString());
};
Run Code Online (Sandbox Code Playgroud)

它将为此主题创建 2 个订阅,一个是拉,另一个是推送

我的云函数被调用,但我的消息没有得到确认。

根据文档

注意:在成功执行函数后,Cloud Functions 会在内部确认消息。有关如何使用重试处理失败的信息,请参阅重试后台函数。

所以函数应该自动确认它不工作。

这个流程有什么问题。我究竟做错了什么?

谢谢

google-cloud-pubsub google-cloud-functions

5
推荐指数
1
解决办法
889
查看次数

从谷歌云功能访问 Firebase 管理员

我正在尝试从 GOOGLE 云功能访问和更新我的 firebase 数据库,但它不起作用。

我编写了一个云函数,在其中初始化了 firebase-admin。

我必须提供service_account来初始化管理员。

我是initializing我的 firebase 应用程序

admin.initializeApp({
   credential: admin.credential.cert(service_account),
  databaseURL: "",
  databaseAuthVariableOverride: {
    uid: ""
  }
});
Run Code Online (Sandbox Code Playgroud)

我在 GOOGLE 云功能中没有我的服务帐户路径。

是否有任何方法可以从 GOOGLE 云功能访问 firebase?

谢谢

firebase firebase-authentication firebase-realtime-database google-cloud-functions

2
推荐指数
1
解决办法
1650
查看次数