multer icon indicating copy to clipboard operation
multer copied to clipboard

req.files does not exist on request

Open manish153 opened this issue 10 years ago • 7 comments

I am getting this error when trying to upload a file

server\server.ts(31,19): error TS2339: Property 'files' does not exist on type 'Request'.

I can do (res.send(req['files'])); and it works,.. but not on (res.send(req.files));

app.post("/upload", multer({dest: "./uploads/"}).array("uploads", 12), function(req, res) {
    //(res.send(req['files'])); 
    (res.send(req.files)); 
});

manish153 avatar Jun 12 '16 06:06 manish153

Are you using the multer definition file?

LinusU avatar Jun 12 '16 18:06 LinusU

How can I Check? I just installed multer through NPM. Sorry fairly new to this.

manish153 avatar Jun 12 '16 18:06 manish153

Hmm, I actually am not that familiar with how TypeScript works. But I believe that you have to add some kind of definition file since multer is written in ordinary javascript.

Seems like maybe this is it: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/multer/multer.d.ts

LinusU avatar Jun 12 '16 18:06 LinusU

Worked like a charm. Thanks a lot. I just took the file and placed it on the node server and referenced to the correct location of express.d.ts

manish153 avatar Jun 12 '16 19:06 manish153

Glad to hear it 🙌

LinusU avatar Jun 13 '16 05:06 LinusU

@LinusU link broken

shuboy2014 avatar May 10 '18 15:05 shuboy2014

new link: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/multer/index.d.ts

LinusU avatar May 10 '18 20:05 LinusU