【发布时间】:2018-02-09 11:35:43
【问题描述】:
我是 Google 平台的新手,不了解如何使用外部库创建 Google 函数。
我想将 CSV 文件上传到 Cloud Storage,然后触发 Google Cloud Function 以将其与 Google Cloud Storage 中的另一个 CSV 文件联接,并将 JOIN 结果导出到新的 csv 文件并删除重复项。
我已经看到用于 npm 的库“csv-join”和“csv-reorder”,但我不确定如何将它与 Cloud Functions 一起使用,以及是否可能,因为我被困在这一点上。
感谢您的建议。
问候。
这是我的代码:
exports.Test_BQ = (event, callback) => {
const file = event.data;
if (file.resourceState === 'not_exists') {
console.log(`File ${file.name} deleted.`);
} else if (file.metageneration === '1') {
const reorder = require('csv-reorder');
reorder({
input: 'https://storage.googleapis.com/staging.XXXXX.appspot.com/test.csv',
output: 'https://storage.googleapis.com/staging.XXXXX.appspot.com/test_2.csv',
sort: 'policyID',
type: 'string',
descending: false,
remove: true,
metadata: false
});
}
callback();
};
我收到此错误:
TypeError: promisify 不是 Object 的函数。 (/user_code/node_modules/csv-reorder/lib/read.js:6:18) 在 Module._compile (module.js:570:32) 在 Object.Module._extensions..js (module.js:579:10 ) 在 Module.load (module.js:487:32) 在 tryModuleLoad (module.js:446:12) 在 Function.Module._load (module.js:438:3) 在 Module.require (module.js:497 :17) 在 Object 的 require (internal/module.js:20:19) 处。 (/user_code/node_modules/csv-reorder/index.js:4:14) 在 Module._compile (module.js:570:32)
现在我只测试“csv-reorder”来了解这个外部库是如何工作的。我在本地得到了结果,但在云端没有。
【问题讨论】:
标签: node.js csv google-cloud-platform google-cloud-storage