繁体   English   中英

如何通过角度js上传多个文件

[英]How to upload multiple file through angular js

这是我的角度代码。文件上传是针对单个文件发生的,但添加其他两个文件的情况还没有发生。请你帮我解决这个问题。请帮助我,我很难被卡住。

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

我个人使用angular-file-upload ,这个指令可以轻松上传多个文件。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM