我正在尝试下载一些已上传到我的 Google Cloud Storage(也称为存储桶)的图像。我无法在我的任何设备上使用 .ref() 方法,const storage
或者const bucket
因为它们是管理 SDK 的一部分。admin.storage 只有方法 .bucket() ( https://firebase.google.com/docs/reference/admin/node/admin.storage.Storage )。
我可以访问存储桶。bucket.getFiles() 工作,结果出来是一个带有大量元数据(如文件名、存储桶所有者等)的文件对象数组。如何从云存储中获取我的图像并将它们插入到 html 对象中?
var admin = require("firebase-admin");
var serviceAccount = require("./randomDB-f12d3-admin-correctly-working.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://randomDB-f12d3.firebaseio.com",
storageBucket: "randomDB-f12d3.appspot.com"
});
const gcs = require("@google-cloud/storage");
gcs.projectId = "randomDB-f12d3";
gcs.keyFilename = "randomDB-f12d3-firebase-admin-correctly-working.json";
exports.getFile = functions.https.onRequest((req, res) => {
cors(req, res, () => {
if (req.method !== "GET") {
return res.status(500).json({
message: "Not allowed"
});
}
const storage = admin.storage();
const bucket = admin.storage().bucket();
bucket.getFiles().then((result)=>{
console.log(result);
res.send(result);
});
});
});