Я пытаюсь Node.js загрузить несколько файлов из локального каталога моей виртуальной машины Google Compute Engine в корзину 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. И все же почему ошибка?
Любая помощь будет серьезно оценена!