Cant get file upload to work using nervgh library

Issue

I am new to angularJs. I am trying to upload a .tar file to my server using nervgh angular file upload library. I used the code as is from the example but I get a 500 exception from the server stating Invalid Archive File format. However, I am able to upload the same file & send the same request via POSTMAN. Any Help would be appreciated !
Angular Version : 1.5.8

My View

/*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>

My Controller

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*/


}]);

Solution

It’s a problem with the server, not angular. Show us your server-side script.

Answered By – Patryk DobrzyƄski

Answer Checked By – Robin (AngularFixing Admin)

Leave a Reply

Your email address will not be published.