Multer is working in simple nodejs app but when I am trying to use multer in firebaseapp, the same code is not working. I have added only a single line. const functions = require('firebase-functions'); And hence it shows req.file is undefined. So any body tell me how to solve this problem or suggest me any other package that can replace multer and should work fine in firebaseapp. Thank You.
const functions = require('firebase-functions');
const express = require('express');
const multer = require('multer');
const ejs = require('ejs');
const path = require('path');
var upload = multer({ dest: __dirname })
// Init app
const app = express();
// EJS
app.set('view engine', 'ejs');
// Public Folder
app.use(express.static('./public'));
app.get('/', (req, res) => res.render('index'));
//upload file testing
app.post('/upload', upload.single('myImage'), function (req, res, next) {
// req.file is the `avatar` file
// req.body will hold the text fields, if there were any
if(req.file){console.log(req.file.originalname)}
else {console.log("file not found")}
res.send(req.file.originalname)
})
exports.app = functions.https.onRequest(app);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css">
<title>Node File Uploads</title>
</head>
<body>
<div class="container">
<h1>File Upload</h1>
<%= typeof msg != 'undefined' ? msg : '' %>
<form action="/upload" method="POST" enctype="multipart/form-data">
<div class="file-field input-field">
<div class="btn grey">
<span>File</span>
<input name="myImage" type="file">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text">
</div>
</div>
<button type="submit" class="btn">Submit</button>
</form>
<br>
<img src="<%= typeof file != 'undefined' ? file : '' %>" class="responsive-img">
</div>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>
</body>
</html>