2017-09-03 85 views
0

我正在學習ExpressJS,並且正在嘗試通過Node將圖像上傳到Firebase存儲。如何將圖像從Expressjs更新到Google雲端存儲/ Firebase存儲

我收到錯誤:firebase.storage().ref() is not a function,並搜索它我發現這些Topic,並發現firebase存儲不支持的節點。

現在,這是問題:我有一個文件對象收到的HTML輸入文件,但我根本不知道如何上傳到谷歌雲存儲。我如何做到這一點?

我發現的解決方案都使用文件路徑名來上傳,但我喜歡上傳文件對象(文件)。

我的代碼:

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!'); 
//}); 
}); 

由於到現在爲止。

+0

你可以在這裏找到選項:https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload – voscausa

+1

您可以使用Google Cloud Storage節點SDK。 https://github.com/GoogleCloudPlatform/google-cloud-node#cloud-storage-ga –

回答

0

我在發佈此主題之前已看到這些文檔。我決定測試通過文件路徑名稱上傳基本圖像,如: home/pedro/Downloads/outros icones/1532.png 使用此code,我收到錯誤:無法驗證錯誤,但我下載了OAuth2.0的keyfile.json並對其進行了配置。

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的。

我現在很迷茫......

相關問題