使用nervgh库无法上传文件

时间:2016-08-15 21:37:02

标签: angularjs angular-file-upload

我是angularJs的新手。我正在尝试使用nervgh angular file upload库将.tar文件上传到我的服务器。我从示例中使用了代码,但是我从服务器获得了500异常,说明了无效的归档文件格式。但是,我可以上传相同的文件&通过POSTMAN发送相同的请求。任何帮助,将不胜感激 ! 角度版本:1.5.8

我的观点

/*View : apps.html*/
    <div class="row">
        <div class="col-md-3">
            Single
            <input type="file" nv-file-select="" uploader="uploader" />
        </div>
        <button type="button" class="btn btn-success btn-s" ng-click="uploader.uploadAll()" ng-disabled="!uploader.getNotUploadedItems().length">
            <span class="glyphicon glyphicon-upload"></span> Upload all
        </button>
    </div>

我的控制器

angular.module('testAngularLmApp')
.controller('AppsCtrl', ['$scope', 'FileUploader', 'appsService', 'tokenService', function($scope, FileUploader, appsService, tokenService) {
    var token = tokenService.getToken(); //LoginCtrl.getToken();

    /*File UPload Functions*/

    var headers = {
        'X-Token-Id': token,
        'X-Connector-Id': 'App5',
        'Content-Type': undefined
    };

    var uploader = $scope.uploader = new FileUploader({
        url: '/api/v2/apps',
        headers: headers,
        transformRequest: angular.identity,
        method: 'POST'
    });

    uploader.onWhenAddingFileFailed = function(item /*{File|FileLikeObject}*/ , filter, options) {
        console.info('onWhenAddingFileFailed', item, filter, options);
    };
    uploader.onAfterAddingFile = function(fileItem) {
        console.info('onAfterAddingFile', fileItem);
    };
    uploader.onAfterAddingAll = function(addedFileItems) {
        console.info('onAfterAddingAll', addedFileItems);
    };
    uploader.onBeforeUploadItem = function(item) {
        console.info('onBeforeUploadItem', item);
        item.formData.push(headers);
    };
    uploader.onProgressItem = function(fileItem, progress) {
        console.info('onProgressItem', fileItem, progress);
    };
    uploader.onProgressAll = function(progress) {
        console.info('onProgressAll', progress);
    };
    uploader.onSuccessItem = function(fileItem, response, status, headers) {
        console.info('onSuccessItem', fileItem, response, status, headers);
    };
    uploader.onErrorItem = function(fileItem, response, status, headers) {
        console.info('onErrorItem', fileItem, response, status, headers);
    };
    uploader.onCancelItem = function(fileItem, response, status, headers) {
        console.info('onCancelItem', fileItem, response, status, headers);
    };
    uploader.onCompleteItem = function(fileItem, response, status, headers) {
        console.info('onCompleteItem', fileItem, response, status, headers);
    };
    uploader.onCompleteAll = function() {
        console.info('onCompleteAll');
    };

    console.info('uploader', uploader);

    /*Actually upload a file*/
    $scope.uploader.uploadAll();
    /*End of file upload*/


}]);

1 个答案:

答案 0 :(得分:1)

这是服务器的问题,而不是角度。向我们展示您的服务器端脚本。