我想使用带有$ resource的AngularJS从客户端上传文件。
需要将FormData发送到服务器。
我正在尝试使用以下代码
<input file-model="uploadingfile" type="file"/><br/>
angular.module('upload.upload', [
])
.directive('fileModel', ['$parse', function ($parse) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var model = $parse(attrs.fileModel);
var modelSetter = model.assign;
element.bind('change', function(){
scope.$apply(function(){
modelSetter(scope, element[0].files[0]);
});
});
}
};
}]);
var myservercall = $resource("my/rest/path/:filename", { filename: '@filename'});
var file = $scope.uploadingfile;
var fd = new FormData();
fd.append('upload', file);
myservercall.save({filename: file.name}, here i don't know how to send the form data);
我如何使这项工作?