I am using connect-multiparty with Express4/Node/Angular. Running it locally, on a file upload, I get a 'ENOENT open' error when I specify an 'uploadDir', but it works with the default multipart().
Error: ENOENT, open 'upload_image_dir/83785-xjohos.png' POST /api/providers/me/543695a47be1540000a4fedc/upload/image 400 20ms - 63b
code: (built on top of generator-angular-fullstack) var config = require('../../config/environment'); var multipart = require('connect-multiparty'); var router = express.Router();
// ... more routes
router.post('/me/:id/upload/image', auth.isAuthenticated(), multipart({ uploadDir: './upload_image_dir' }), controller.upload_image);
Where am I going wrong?
Old posts refer to problems due to BodyParser, but that is not so with express 4 and latest connect-multiparty.
If the error means 'no directory exists', then do I need to manually create the dir? the examples and documentation dont mention it.
Should I be using relative paths like ive used above?
EDIT 1: I tried the following and still the same error:
router.post('/me/:id/upload/image', auth.isAuthenticated(), multipart({ uploadDir: __dirname + '../../../upload_image_dir' }), controller.upload_image);
__dirname
does not add a /
to the end.
Change this:
__dirname + '../../../upload_image_dir'
to this:
__dirname + '/../../../upload_image_dir'