Hi, sorry, I did not illustrate the input lf-ng-md-file explicitly.
angular , ajax.
, - "lf-files", , .
"lf-files" , lfFileName ( ), lfFile ( ) lfDataUrl ( ) .
"lf " $watch.
html:
<lf-ng-md-file-input lf-files='files' multiple> </lf-ng-md-file-input>
javascript:
app.controller('MyCtrl',function($scope){
$scope.$watch('files.length',function(newVal,oldVal){
console.log($scope.files);
});
});
, , , , , .
javascript:
app.controller('MyCtrl',function($scope){
...
$scope.onSubmit = function(){
var formData = new FormData();
angular.forEach($scope.files,function(obj){
formData.append('files[]', obj.lfFile);
});
$http.post('./upload', formData, {
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
}).then(function(result){
},function(err){
});
};
...
});
node.js(express + formidable) , "Formidable" - node , "Multer".
:
var express = require('express');
var formidable = require('formidable');
var app = express();
app.use(express.static(__dirname + '/public'));
...
app.post('/upload',function(req,res){
var form = new formidable.IncomingForm();
form.uploadDir = __dirname +'/public/uploads';
form.parse(req, function(err, fields, files) {
});
form.on ('fileBegin', function(name, file){
file.path = form.uploadDir + "/" + file.name;
});
form.on ('end', function(){
res.sendStatus(200);
});
});
...
, .