javascript - Using multer cause error when running app -
im having node application express use multer module https://github.com/expressjs/multer
in app.js
file put following:
var mulstorage = require("./utils/store"), var upload = multer({ storage: mul.storage, dest: 'uploads/' }); app.use(upload.single('file'));
the store.js
file following
var multer = require('multer'); var stor = multer.diskstorage({ destination: function (req, file, cb) { cb(null, './uploads/') }, filename: function (req, file, cb) { var filename = file.originalname; var fileextension = filename.split(".")[1]; cb(null, date.now() + "." + fileextension); } }) module.exports = { stor: stor }
when run request using postman got following error:
error: enoent: no such file or directory, open 'c:\users\c45669\webstormprojects\app\uploads\1454935327214.zip'
at error (native)
why multer doesn't create folder if doesn't exist??
if i'm creating upload folder under root manually working...
btw, when change following , remove storage: mul.storage,
working, need storage determine file name ...
var upload = multer({ //storage: mul.storage, dest: 'uploads/' });
even if remove property dest multer object , keep storage got same error...
why multer doesn't create folder if doesn't exist??
this in documentation (link) :
note: responsible creating directory when providing destination function. when passing string, multer make sure directory created you.
i don't know why author made decision, see not bug.
you can use fs
module create directories.
Comments
Post a Comment