javascript - File upload with nodejs, express and angular using dropzone -
i'm having trouble getting file recognized server side node.
specifically when accessing request data, (req.files or req.body)
here snippets if has advice.
html:
<form action="/upload" class="dropzone" drop-zone id="file-dropzone"></form>
angular controller:
'use strict'; angular.module('app') .controller('samplectrl', function ($scope, $http) { }) .directive('dropzone', function() { return function(scope, element, attrs) { $(element).dropzone({ url: "/upload", maxfilesize: 100, maxthumbnailfilesize: 5 }); } });
node router:
'use strict'; var express = require('express'); var controller = require('./import.controller'); var router = express.router(); router.post('/', controller.import); module.exports = router;
node controller:
'use strict'; var express = require('express'), _ = require('lodash'), fs = require('fs'), path = require('path'), multer = require('multer'), bodyparser = require('body-parser'), app = express(); app.use(bodyparser.urlencoded({extended: true})); exports.import = function(req, res) { console.log(req.files); // responds 'undefined' console.log(req.body); // responds {} };
thanks in advance
you have use file upload middleware express unpack part of request. multer
docs:
var express = require('express') var multer = require('multer') var app = express() app.use(multer({ dest: './uploads/'})); console.log(req.body) console.log(req.files)
Comments
Post a Comment