I've created a Firebase Function that is supposed to fire when I add a new document, and then the function creates an image by pulling some data from the document. I could have sworn this was working yesterday, but now when I upload a document, the Function throws an error telling me that "ref" is not a function. I've followed the online Firebase docs and I think I have what I need here (ref is being required) so I'm confused as to why I'm getting the error. Here are the relevent bits...
const { getStorage, ref } = require("firebase-admin/storage"); // <- ref is required
const { initializeApp } = require("firebase-admin/app");
initializeApp();
const storage = getStorage();
exports.createFbAd = onDocumentCreated("/quizzes/{documentId}", async (event) => {
// Create a new image and store it in Storage
const canvasWidth = 1200; // Set the canvas width
const canvasHeight = 630; // Set the canvas height
const canvas = createCanvas(canvasWidth, canvasHeight);
const ctx = canvas.getContext('2d');
logger.log("Created canvas");
// Get the reference to the ad image in Firebase Storage
const fbAdRef = ref(storage, 'fb ad base.jpg'); // ERROR 'ref is not a function'
...
...
});
Am I missing something obvious?
The Node.js Admin SDK for Cloud Storage is not a variant of the client-side SDKs, but a variant of the GCP SDK. So you'll want to use this documentation and this to base your code on.