我正在尝试将一个HTML文件写入Google Cloud Storage,而不将该文件保存在节点应用程序中。我需要创建一个文件并立即上传到云存储。我尝试使用fs.writeFileSync()方法,但它会在我的应用程序中创建文件,而我不希望这样。
const res = fs.writeFileSync("submission.html", fileData, "utf8");
GCS.upload(res, filePath);我希望直接在云存储中保存一个HTML文件。你能给我推荐一种正确的方法吗?
发布于 2019-06-20 02:38:04
我认为解决方案是使用包装createWriteStream的file.save方法,所以这应该是可行的。
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() {});https://stackoverflow.com/questions/56673612
复制相似问题