这里的错误TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须为字符串类型收到的类型对象

问题描述

嗨,我正在尝试使用以下给定代码将Base64文件从NodeJs上传到Firebase存储(Google云存储)。但是我收到一个错误提示

此处错误TypeError [ERR_INVALID_ARG_TYPE]:“ path”参数必须 是字符串类型。在validateString处收到的类型对象 (internal / validators.js:125:11)

代码是:

const key = require('../key.json');
const {Storage} = require('@google-cloud/storage');
//var gcs = require('@google-cloud/storage');
exports.uploadVideo = functions.https.onRequest((req,res) => {

    const gcs =new Storage({
        projectId: "<my-project-id>",keyFilename: key
      });

      const bucket = gcs.bucket("example.appspot.com");
      const gcsname = 'test.pdf';
      const file = bucket.file(gcsname);
      var pdfdata = "xNC9YUmVmU3RtIDE1NzQ+Pg0Kc3RhcnR4cmVmDQoyMTY5DQolJUVPRg==";
      var buff = Buffer.from(pdfdata,'binary').toString('utf-8');
      const stream = file.createWriteStream({
        Metadata: {
          contentType: 'application/pdf'
        }
      });

      stream.on('error',(err) => {
        console.log("Error here",err);
      });
      stream.on('finish',() => {
        console.log(gcsname);
      });
      stream.end(new Buffer.from(buff,'base64'));})

有人可以建议我出路吗?我不明白这个问题。 谢谢

解决方法

错误显示为“ TypeError [ERR_INVALID_ARG_TYPE]:“ path”参数必须为字符串类型。收到的未定义”

它试图从路径中获取,您应该在寻找路径时将这些变量添加到.env文件中的根目录中。.它会获取正确的变量。让我知道您是否还有困难。.

您可以参考Express Routing with Google Cloud Functions以获得更多详细信息。

,

这意味着程序期望path自变量的类型为string,例如:"path/to/whatever"。而您给它一个对象-例如:{ path: "path/to/whatever" }

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...