我想在我的 Web 应用程序中实现文件上传,我angular.js
在客户端和spring mvc
服务器端使用。
我设法通过使用https://github.com/danialfarid/angular-file-upload使单个文件上传和多个文件上传工作。问题是,当我上传多个文件时,每个文件都作为单独的请求向我提出(在阅读示例代码后这是显而易见的事件):
//inject angular file upload directives and service.
angular.module('myApp', ['angularFileUpload']);
var MyCtrl = [ '$scope', '$upload', function($scope, $upload) {
$scope.onFileSelect = function($files) {
//$files: an array of files selected, each file has name, size, and type.
for (var i = 0; i < $files.length; i++) {
var $file = $files[i];
$scope.upload = $upload.upload({
url: 'server/upload/url', //upload.php script, node.js route, or servlet url
// method: POST or PUT,
// headers: {'headerKey': 'headerValue'}, withCredential: true,
data: {myObj: $scope.myModelObj},
file: $file,
//(optional) set 'Content-Desposition' formData name for file
//fileFormDataName: myFile,
progress: function(evt) {
console.log('percent: ' + parseInt(100.0 * evt.loaded / evt.total));
}
}).success(function(data, status, headers, config) {
// file is uploaded successfully
console.log(data);
})
//.error(...).then(...);
}
}
}];
所有文件都有一个迭代。
现在我想知道是否有可能以某种方式将多个文件作为一个请求上传。