multer icon indicating copy to clipboard operation
multer copied to clipboard

Multer.any() not working ?

Open roby2001 opened this issue 10 years ago • 9 comments

I have a server to which I wish to upload a file but without checking the input fieldname. I using typescript so formdata isn't really an option at the moment. I tought simply changing my upload.single('picture') to upload.any() should fix it, but if I add a console.log in the destination: of my upload it never shows ( doesn't get there ). Why is this happening when trying to use multer.any? Also if you know of any workarounds to upload files from typescript without refreshing the page it would be great!

roby2001 avatar Feb 03 '16 13:02 roby2001

single names the file req.file and any names it req.files (note the extra s), could that be it?

LinusU avatar Feb 03 '16 14:02 LinusU

@LinusU If I try to use either req.file or req.files it says they are not defined ( typescript error when compiling )

roby2001 avatar Feb 03 '16 16:02 roby2001

Hmm, does it work with .single? What definition file are you using?

LinusU avatar Feb 04 '16 05:02 LinusU

Same thing. I'm trying to avoid setting the filename, but when i use Multer({ ... }).any() I get back an error saying any is not a function. When i set the express middleware of post to .any without the function call, I get back that [object Undefined] is not a function.

funkjunky avatar Feb 08 '16 05:02 funkjunky

@funkjunky I don't think that you have the same thing since @roby2001 has a problem when compiling his typescript, not when running javascript. In your case, it seems like you are using an old version of multer, can you confirm that you are running version 1.1.0 which introduced the .any() function?

LinusU avatar Feb 08 '16 07:02 LinusU

I'm not. Sorry about the troubles. I'm using single and it's working fine and dandy now. Super late night programming is dangerous =P Feel free to delete all of my posts on this thread.

funkjunky avatar Feb 08 '16 08:02 funkjunky

Hehe, no problem, we've all been there :)

LinusU avatar Feb 08 '16 08:02 LinusU

I managed to get my things working with .single . However typescript doesn't allow you to access req.file / req.files since they don't actually exist before multer. You should talk to the typescript complier guys.

roby2001 avatar Feb 08 '16 12:02 roby2001

Hmm, yeah I wonder how that works... Oh well, at least this should be closed since the issue is with TypeScript...

LinusU avatar Feb 08 '16 13:02 LinusU