I tried to upload file as well as text data from the api,so i have write multipart api for getting file and text data from the res in nodejs for getting file i am using multer module but now i am getting undefined or null in req.files & req.file. I'm trying to upload a file using multer and below are the code snippets :
const express = require('express');
const app = express();
var multer = require('multer');
var upload = multer();
app.post('/api/upload', upload.single('photo'),function (req, res, next) {
let data = req.body;
let file = req.file;
console.log(data)
console.log(file)
return res.status(200).send(data)
})
Response of this api always return null and undefined
functions: Beginning execution of "app"
> [Object: null prototype] {}
> undefined
and i am passing two parameters from the api
- photo which is a type of file
- name parameter which is type of string
and i have pass this data from Form-data formate
hope anyone help my soon