[英]How update an image from Expressjs to Google Cloud Storage / Firebase Storage
我正在學習ExpressJS,並嘗試通過Node將圖像上傳到Firebase存儲。
我收到了錯誤消息: firebase.storage().ref() is not a function
,搜索它時發現了這些Topic,並發現Node不支持Firebase存儲。
現在的問題是:我有一個通過html輸入文件接收的文件對象,但是我根本不知道如何將其上傳到Google Cloud Storage。 我該怎么辦?
我找到的所有解決方案都使用文件路徑名進行上傳,但是我喜歡上傳文件對象(文件)。
我的代碼:
req.pipe(req.busboy);
req.busboy.on('file', function (fieldname, file, filename) {
console.log("Uploading: " + filename);
// Trying GCS
var remoteReadStream = bucket.file('giraffe.jpg').createReadStream();
console.log(remoteReadStream);
//var localWriteStream =
fs.createWriteStream('/photos/zoo/giraffe.jpg');
//remoteReadStream.pipe(localWriteStream);
// Trying Firebase
//storageRef.put(file).then(function(snapshot) {
// console.log('Uploaded a blob or file!');
//});
});
謝謝直到現在。
在發布此主題之前,我已經看過這些文檔。 我決定通過文件路徑名測試上傳基本圖像,例如: home/pedro/Downloads/outros icones/1532.png
使用此代碼 ,我收到錯誤:無法確認錯誤,但我下載了OAuth2的keyfile.json
.0並對其進行配置。
var x = '/home/pedro/Downloads/outros icones/1532.png'
var localReadStream = fs.createReadStream(x);
var remoteWriteStream = bucket.file('zebra.jpg').createWriteStream();
localReadStream.pipe(remoteWriteStream);
變量bucket
是已配置的存儲桶參考(所有這些文檔的開頭),而fs
是fs
的要求。
我現在很困惑
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.