【发布时间】:2013-08-30 01:59:07
【问题描述】:
我正在使用this tutorial。 问题是该指令返回的是上传对象,基本上是选择文件时自动触发上传。
虽然对 AngularJS 的了解比我更深的人可以想出一种方法来手动触发 bluimp 的上传事件,可能是通过按键,或者在回调中。
【问题讨论】:
标签: angularjs file-upload angularjs-directive
我正在使用this tutorial。 问题是该指令返回的是上传对象,基本上是选择文件时自动触发上传。
虽然对 AngularJS 的了解比我更深的人可以想出一种方法来手动触发 bluimp 的上传事件,可能是通过按键,或者在回调中。
【问题讨论】:
标签: angularjs file-upload angularjs-directive
你能看一下@下面的网址,他们正在使用开始按钮上传文件吗:
【讨论】:
不确定问题出在哪里,但这可能会为您省去在 Angular 中确定文件上传的麻烦:
您可以使用简单/轻量级的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);
});
}
}
}];
【讨论】: