0

I have a file nodejs that adds the picture(lion.jpg) to Cloud Storage

const firebase = require('firebase-admin');
const express = require('express');
const app = express();
const serviceAccount= require("./key9525")  

firebase.initializeApp({
  credential: firebase.credential.cert(serviceAccount),
  databaseURL: "https://myadress.firebaseio.com"  //example adress
});

const bucketName = 'myadress.appspot.com';
const filename ='./lion.jpg';     //example file

async function uploadFile() {

  const {Storage} = require('@google-cloud/storage');
  const storage = new Storage();

  await storage.bucket(bucketName).upload(filename, {

    gzip: true,
    metadata: {
      cacheControl: 'public, max-age=31536000',
    },
  });
  console.log(`${filename} uploaded to ${bucketName}.`);
}

uploadFile();

and I have a file that allows me to select and upload a photo for example in postman

const express = require('express');
const app = express();
const port = 3000;

app.get('/', (req, res) => {
    res.send('hello people');
});

app.listen(port, () => {
    console.log('listening to the port: ' + port);
});

var multer = require('multer');
var upload = multer({dest:'uploads/'});

app.post('/single', upload.single('profile'), (req, res) => {
  try {
    res.send(req.file);
  }catch(err) {
    res.send(400);
  }
}

How I can connect these codes so that after loading the nodejs file, then selecting the file in postman, the file was upload in firebase? thank you for all tips

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Kacper
  • 3
  • 2

1 Answers1

0

You have to pass the multer as the middleware to your POST call as like what you did. Please refer this link

GRS
  • 1,829
  • 1
  • 9
  • 23