Omer Ozer
Omer Ozer

Reputation: 465

Multer not creating file on request

I have the following setup for a router and multer midware isn't creating the file on request so

req.file

is always undefined.

    const multer = require('multer');

let storage = multer.memoryStorage();

function fileFilter (req, file, cb) {
    if(file.mimetype === 'image/jpeg' || file.mimetype === 'image/png'){
        cb(null,true);
        return;
    }
    cb(new Error('wrong file type:not PNG or JPEG'),false);
}

const upload = multer({
    storage : storage,
    fileFilter : fileFilter
});

this.getServer().post('/vendor/profile/logo',upload.single('imageFile'),jwt,(req, res) => {
                this.addCompanyLogo(req).then(user => {
                    res.status(200).send(user);
                }).catch(err => {
                    console.log(err);
                    res.status(err.status).send(err.error);
                });
            });

I also have bodyparser at app level.

 server = express();
        server.use(bodyParser.json());
        server.use(bodyParser.urlencoded({ extended: true }));
        server.use(cors());

I'm making the request using postman :

enter image description here

so far nothing has worked. I tried removing bodyparser thinking that's the issue, didn't work. tried reordering the middleware , that also didn't work.

Upvotes: 0

Views: 106

Answers (1)

Omer Ozer
Omer Ozer

Reputation: 465

The issue turned out the be related to the my local file path containing characters not supported by postman such as ö .

Upvotes: 0

Related Questions