2016-07-07 31 views
0

爲了我的應用程序的正確安全性,我已經被迫爲firebase設置了一個小型nodejs服務器,但問題尚未解決.... firebase服務器sdk不支持存儲apis。我讀到這是一個gcloud存儲apis,因爲firebase使用相同的服務。firebase nodejs服務器和gcloud存儲 - 獲取元數據

在服務器端獲取文件定製元數據很重要,因爲我必須讀取和更新它們。我沒有找到合適的函數來獲取文件元數據。在客戶端sdk很簡單

// Create a reference to the file whose metadata we want to retrieve 
var forestRef = storageRef.child('images/forest.jpg'); 

// Get metadata properties 
forestRef.getMetadata().then(function(metadata) { 
    // Metadata now contains the metadata for 'images/forest.jpg' 
}).catch(function(error) { 
    // Uh-oh, an error occurred! 
}); 

和在gcloud存儲中我可以使用什麼函數?感謝

回答

1

你要使用gcloudgetMetadata()方法:

var gcloud = require('gcloud'); 

// Initialize GCS 
var gcs = gcloud.storage({ 
    projectId: 'my-project', 
    keyFilename: '/path/to/keyfile.json' 
}); 

// Reference an existing bucket 
var bucket = gcs.bucket('foo.appspot.com'); 

// Reference to a file 
var file = bucket.file('path/to/my/file'); 

// Get the file metadata 
file.getMetadata(function(err, metadata, apiResponse) { 
    if (err) { 
    console.log(err); 
    } else { 
    console.log(metadata); 
    } 
}); 
+0

完美謝謝:) – DThink