我正在尝试将 HTML 文件写入 Google Cloud Storage,而不将文件保存在我的节点应用程序中。我需要创建一个文件并立即上传到云存储。我尝试使用fs.writeFileSync()方法,但它在我的应用程序中创建了文件,我不想要那样。const res = fs.writeFileSync("submission.html", fileData, "utf8");
GCS.upload(res, filePath);我希望直接在云存储中保存一个 HTML 文件。你能向我推荐正确的方法吗?
1 回答

凤凰求蛊
TA贡献1825条经验 获得超4个赞
我相信的解决方案是使用file.savewraps的方法createWriteStream,所以这应该有效。
const storage = require('@google-cloud/storage')();
const myBucket = storage.bucket('my-bucket');
const file = myBucket.file('my-file');
const contents = 'This is the contents of the file.';
file.save(contents, function(err) {
if (!err) {
// File written successfully.
}
});
//-
// If the callback is omitted, we'll return a Promise.
//-
file.save(contents).then(function() {});
添加回答
举报
0/150
提交
取消