2015-12-30 84 views
0

我卡在我的应用程序中,我想用wcf服务使用角度js上传文件,我使用wcf服务来操纵数据库。 我已经创建了一个文件上传指令。如何使用wcf服务在angularjs中上传文件?

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

和服务调用Post方法。

myApp.service('fileUpload', ['$http', function ($http) { 
    this.uploadFileToUrl = function (file, uploadUrl) { 
     var fd = new FormData(); 
     fd.append('file', file); 
     debugger; 
     $http.post('http://localhost:50202/WcfService/Service1.svc/fileUpload', fd, { 
      transformRequest: angular.identity, 
      headers: { 'Content-Type': undefined } 
     }) 
     .success(function() { 
     }) 
     .error(function() { 
     }); 
    } 
}]); 

所以问题是,当文件转换为字节wcf服务时说这个大小太大了。 所以任何人都可以帮助我,我怎样才能将文件片段分块并上传。

回答

0

你需要增加在Web.config的最大消息长度:

<configuration> 
    <system.web> 
    <httpRuntime maxMessageLength="409600" 
    executionTimeoutInSeconds="300"/> 
    </system.web> 
</configuration> 

这将设置最大消息长度为400 MB(参数是KB)。

相关问题