You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to send two documents using postman to the backend and store one file on firebase and other on cloudinary using different configurations but i am encountering this error. If anyone has solution to this problem then Please!! do provide.
The text was updated successfully, but these errors were encountered:
In the error message, I see fiieldname = profile, but that route handler is expecting a fileldname of file too. Are you trying to upload multiple files in 1 request? have you tried using upload.array?
`const express = require('express')
const mongoose = require('mongoose')
const jwt = require('jsonwebtoken')
const fetchadmin = require('../../middleware/fetchadmin');
const router = express.Router();
const admin = require("firebase-admin");
const multer = require('multer');
const serviceAccount = require("./serviceAccountKey.json");
const Admin = mongoose.model('Admin');
const Doctor = mongoose.model('Doctor');
const cloudinary = require('../../helper/imageUpload')
// Profile Photo Storage
const imageStorage = multer.diskStorage({});
const fileFilter = (req, file, cb) => {
console.log(file)
if (file.mimetype.startsWith('image')) {
cb(null, true);
} else {
cb('invalid image file!', false);
}
};
const uploads = multer({ storage: imageStorage, fileFilter });
//File Storage
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
storageBucket: "medease-9368b.appspot.com",
});
const bucket = admin.storage().bucket();
const storage = multer.memoryStorage();
const upload = multer({ storage: storage });
router.post('/adddoctor', fetchadmin, uploads.single('profile'), upload.single("file"), async (req, res) => {
const file = req.file;
if (!req.user)
return res
.status(401)
.json({ success: false, message: 'unauthorized access!' });
if (!file) {
return res.status(400).send("No file uploaded.");
}
//File Upload
const fileRef = bucket.file(file.originalname);
const blobStream = fileRef.createWriteStream();
blobStream.on("error", (error) => {
res.status(500).send("File upload error: " + error);
});
blobStream.on("finish", () => {
fileRef.makePublic().then(async () => {
const med_license =
https://storage.googleapis.com/${bucket.name}/${fileRef.name}
;});
blobStream.end(file.buffer);
});
module.exports = router`
I am trying to send two documents using postman to the backend and store one file on firebase and other on cloudinary using different configurations but i am encountering this error. If anyone has solution to this problem then Please!! do provide.
The text was updated successfully, but these errors were encountered: