ngfileupload调用文件计数的上传时间

时间:2016-08-24 23:19:43

标签: angularjs node.js express ng-file-upload

上传被称为我们选择的计数次数文件,例如,如果我选择了3个文件,我注意到帖子请求被调用了9次

Server.js

var multer  = require('multer');

var storage = multer.diskStorage({
destination: function (req, file, callback) {
    callback(null, './myfolder/files/');
},
/*rename: function(fieldname, filename){
    return filename;
}*/
filename: function (req, file, callback) {
    console.log(file);
    callback(null, file.originalname);
}
});

var upload = multer({ storage : storage});

app.post('/uploadFile', upload.single('files'), function (req, res, next)  {
// req.body contains the text fields
//res.status(200).send();
});

在控制器中注入了ngifleupload

angular.module('itemEditor.controllers')
.controller('ItemEditorCtrl', [
    '$scope',
    '$rootScope',
    '$modal',
    '$timeout',
    'Upload',
    function($scope, $rootScope, $modal, $timeout, Upload) {
        'use strict';
        $scope.uploadFiles = function(files, errFiles) {
            console.log('uploading files');
            $scope.files = files;
            $scope.errFiles = errFiles;
            angular.forEach(files, function(file) {
                file.upload = Upload.upload({
                    url: '/uploadFile',
                    arrayKey: '',
                    data: {
                        files: [file]
                    }
                });
                file.upload.then(function(response) {
                    $timeout(function() {
                        file.result = response.data;
                    });
                }, function(response) {
                    if (response.status > 0)
                        $scope.errorMsg = response.status + ': ' + response.data;
                }, function(evt) {
                    file.progress = Math.min(100, parseInt(100.0 *
                        evt.loaded / evt.total));
                });
            });
        }
    }
]);

HTML

<button title="Select & Upload Files" class="btn btn-primary btn-xs"  id="upload-multiple-files" ngf-select="uploadFiles($files, $invalidFiles)" multiple
   accept="image/*" ngf-max-height="1000" ngf-max- size="1MB"> Select & Upload Files
</button>
<br><br>
Files:
<ul>
   <li ng-repeat="f in files" style="font:smaller">
      {{f.name}} {{f.$errorParam}}
      <span class="progress" ng-show="f.progress >= 0">
         <div style="width:{{f.progress}}%"
            ng-bind="f.progress + '%'"></div>
      </span>
   </li>
   <li ng-repeat="f in errFiles" style="font:smaller">{{f.name}} {{f.$error}} {{f.$errorParam}}
   </li>
</ul>
{{errorMsg}}

我改变了

app.post('/uploadFile', upload.array('files'), function (req, res, next)  {
// req.body contains the text fields
//res.status(200).send();
});

app.post('/uploadFile', upload.single('files'), function (req, res, next)  {
// req.body contains the text fields
//res.status(200).send();
});

我也试过

app.post('/uploadFile', upload.array('files'), function (req, res, next)  {
// req.body contains the text fields
res.status(200).send();
});

0 个答案:

没有答案