Node.js && Firebase Storage

0
const admin = require("firebase-admin");
const uuid  = require('uuid-v4');

// CHANGE: The path to your service account
const serviceAccount = require("./serviceAccountKey.json");

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    storageBucket: "fire-practice-436e4.appspot.com"
});

const bucket   = admin.storage().bucket();
const filename = "./miao.png"

async function uploadFile() {

  const metadata = {
    metadata: {
      // This line is very important. It's to create a download token.
      firebaseStorageDownloadTokens: uuid()
    },
    contentType: 'image/png',
    cacheControl: 'public, max-age=31536000',
  };

  // Uploads a local file to the bucket
  await bucket.upload(filename, {
    // Support for HTTP requests made with `Accept-Encoding: gzip`
    gzip: true,
    metadata: metadata,
  });

console.log(`${filename} uploaded.`);
}

uploadFile().catch(console.error);

profile
🇰🇷🇺🇸 #Back-End Engineer

0개의 댓글