我试着找到一种方法来上传一个由php/MySQL服务器生成的PDF文件到我的Google存储桶。www.my_domain.com/file.pdf。我尝试使用下面的代码,但遇到了一些问题,无法正常工作。错误是:path(fs.createWriteStream(destination))必须是字符串或缓冲区。提前感谢您的帮助!
const http = require('http');
const fs = require('fs');
const {Storage} = require('@google-cloud/storage')
const gcs = new Storage({
keyFilename: 'my_keyfile.json'
})
const bucket = gcs.bucket('my_bucket.appspot.com');
const destination = bucket.file('file.pdf');
var theURL = 'https://www.my_domain.com/file.pdf';
var download = function() {
var file = fs.createWriteStream(destination);
var request = http.get(theURL, function(response) {
response.pipe(file);
file.on('finish', function() {
console.log("File uploaded to Storage")
file.close();
});
});
}
2条答案
按热度按时间wmvff8tz1#
我终于找到了解决办法:
nuypyhwy2#
从v7.0.0开始,firebase管理员使用
google-cloud/storage v2.3.0
,即bucket.upload
上的can no longer accept file URLs。我想我也会分享我的解决方案。