中将 CSV 文件从 Cloud Functions 上传到 Cloud Storage?"/>
如何在 Node.js 中将 CSV 文件从 Cloud Functions 上传到 Cloud Storage?
我正在尝试将从 Cloud Function 中的对象创建的 CSV 文件上传到 Cloud Storage 存储桶。我目前正在使用 @google-cloud/storage 库来处理上传。 CSV 文件保存在 Cloud Function 实例的 tmp 文件夹中。
这是我目前的实现
const saveCsv = async () => {
const { Storage } = require('@google-cloud/storage');
const createCsvWriter = require('csv-writer').createObjectCsvWriter;
const data = [
{
name: 'John',
surname: 'Doe',
age: 35,
gender: 'M',
city: 'New York',
},
{
name: 'Jane',
surname: 'Doe',
age: 28,
gender: 'F',
city: 'Los Angeles',
},
];
const csvPath = '/tmp/output.csv';
const csvWriter = createCsvWriter({
path: csvPath,
header: [
{ id: 'orderNumber', title: 'orderNumber' },
{ id: 'zipcode', title: 'zipcode' },
{ id: 'address', title: 'address' },
{ id: 'phoneNumber', title: 'phoneNumber' },
{ id: 'name', title: 'name' },
],
});
csvWriter.writeRecords(data);
const storage = new Storage();
const bucketName = 'order_numbers';
storage.bucket(bucketName).upload(csvPath);
};
exports.uploadToDrive = functions
.https.onRequest(async (req, res) => {
await save(todayIntentData);
});
结果
Function execution took 60001 ms, finished with status: 'error'
回答如下:
更多推荐
如何在 Node.js 中将 CSV 文件从 Cloud Functions 上传到 Cloud Storage?
发布评论