我正在使用本教程。问题是该指令返回上传对象,它基本上会在选择文件时自动触发上传。
我虽然对 AngularJS 的理解比我更深入,但我可以想出一种方法来手动触发 bluimp 的上传事件,可能是通过按键,或者在回调中。
我正在使用本教程。问题是该指令返回上传对象,它基本上会在选择文件时自动触发上传。
我虽然对 AngularJS 的理解比我更深入,但我可以想出一种方法来手动触发 bluimp 的上传事件,可能是通过按键,或者在回调中。
你能看一下@下面的 url,他们正在使用开始按钮上传文件:
不知道问题出在哪里,但这可能会为您省去以角度计算文件上传的麻烦:
您可以使用简单/轻量级的 angular-file-upload指令。它支持带有 FileAPI flash shim 的非 HTML5 浏览器。它还支持拖放和上传进度。
<div ng-controller="MyCtrl">
<input type="file" ng-file-select="onFileSelect($files)" multiple>
</div>
JS:
//inject angular file upload directive.
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];
$upload.upload({
url: 'my/upload/url',
file: $file,
data: {item: $scope.myModel},
headers: {...}
progress: function(e){}
}).then(function(data, status, headers, config) {
// file is uploaded successfully
console.log(data);
});
}
}
}];