Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

upload image to firebase

const { readFileSync } = require("node:fs");
const firebase = require("../firebase");
const {
  getStorage,
  ref,
  uploadBytes,
  getDownloadURL,
} = require("firebase/storage");
const storage = getStorage();
let image = ""
// Create a reference to 'mountains.jpg'
const storageRef = await ref(storage, "images/" + req.file.filename);

    await uploadBytes(storageRef, readFileSync(req.file.path)).then(
      async (snapshot) => {
        await getDownloadURL(snapshot.ref).then((downloadURL) => {
          console.log(downloadURL.toString());
          image = downloadURL.toString();
        });
      }
    );

    return image;
 
PREVIOUS NEXT
Tagged: #upload #image #firebase
ADD COMMENT
Topic
Name
5+3 =