【发布时间】:2019-04-10 15:19:56
【问题描述】:
我正在尝试 Node.js 将多个文件从我的 Google Compute Engine VM 本地目录上传到我已经创建的 GCS 存储桶。每次运行脚本时都会出现以下错误。
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type function
脚本:
`// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');
const fs = require ('fs');
const glob = require('glob');
// The name of the bucket to access, e.g. "my-bucket"
const bucketName = "myBucket";
// Instantiates a client
const storage = new Storage({
projectId: 'myprojectID',
keyFilename: 'my GCS service key'
});
//get files in the local directory of VM
var allfiles = glob('folder/*.js', function (err, files) {
if (err) {
console.log(err);
}
});
// Uploads VM local dir files to the bucket
storage
.bucket(bucketName)
.upload(allfiles)
.then(() => {
console.log(`${allfiles} uploaded to ${bucketName}.`);
})
.catch(err => {
console.error('ERROR:', err);
});'
显然,“上传”过程需要文件路径名作为字符串。但这就是 Glob 函数应该做的事情。仍然为什么是错误?
任何帮助将不胜感激!
【问题讨论】:
标签: node.js api npm google-cloud-storage glob