【问题标题】:How to upload multiple file through angular js如何通过angular js上传多个文件
【发布时间】:2015-04-28 18:51:18
【问题描述】:

这是我的 Angular 代码。正在为单个文件上传文件,但没有发生添加其他两个文件的情况。您能帮我解决这个问题吗?请帮帮我,我被严重卡住了。

$scope.upload = function(){
            console.log("In upload function");
            console.log(deployTaskId);
            $scope.disableUpload = true;

            var uploadUrl = baseurl+"/"+encodeURIComponent(deployTaskId);
            alert(baseurl);
            console.log(uploadUrl);
            alert(uploadUrl);
            var file = $scope.deploy.myFile;
            var fd = new FormData();
            fd.append('file', file);
            var httpRequest = $http({
            method: 'PUT',
            url: uploadUrl ,
            transformRequest: angular.identity,
             headers: {
            'Content-Type': 'application/json',
            'x-api-key': api_key
            },
            data: fd
            })
            .success(function(data, status){

            console.log("Success in uploading task file");
            $scope.disableUpload = false;
            console.log(data);
            console.log("upload Successful");
            })
            .error(function(data, status){
            console.log("Error in uploading task file");
            $scope.disableUpload = false;
            }); 
        };

这是我的指令

task.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]);
                });
            });
        }
    };
}]);

【问题讨论】:

    标签: javascript angularjs upload


    【解决方案1】:

    我个人使用angular-file-upload,这个指令可以很容易地上传多个文件。

    您可以在 README.md 中找到有关如何上传多个文件的示例。

    【讨论】:

      猜你喜欢
      • 2018-11-01
      • 1970-01-01
      • 2016-10-08
      • 1970-01-01
      • 1970-01-01
      • 2019-12-23
      • 1970-01-01
      • 2021-10-18
      • 1970-01-01
      相关资源
      最近更新 更多