1

Im using https://github.com/danialfarid/ng-file-upload plugin to manage my file upload, following is my code.

HTML

<form name="form">
    Single Image with validations
    <div class="button" ngf-select ng-model="file" name="file" ngf-pattern="'image/*'"
         ngf-accept="'image/*'" ngf-max-size="20MB" ngf-min-height="100"
         ngf-resize="{width: 100, height: 100}">Select</div>
    Multiple files
    <div class="button" ngf-select ng-model="files" ngf-multiple="true">Select</div>
    Drop files: <div ngf-drop ng-model="files" class="drop-box">Drop</div>
    <button type="submit" ng-click="upload()">submit</button>
</form>

Controller

// upload on file select or drop
                $scope.upload = function (file) {

                    file = new FormData();
                    file = {'file': file};


                    imageFind.search(file, $scope.documentsOffsetStart, $scope.titleSorting)
                        .then(
                        function (response) {
                            console.log('Success ' + response.config.data.file.name + 'uploaded. Response: ' + response.data);
                        },
                        function (response) {
                            console.log('Error status: ' + response.status);
                        }, function (evt) {
                            console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
                        });

                };

Image find service

  ]).factory('imageFind', [
        'imageService', 'ApiService',
        function (imageService, ApiService) {
            return {
                search: function (file, start, sort) {
                    var formData, params={};
                     if (start == null) {
                        start = 0;
                     }
                     if (sort == null) {
                        sort = "";
                     }

                    var data = {
                        start: start,
                        sort: sort
                    };

                    data = $.param(data);
                    var config = {'Content-Type': undefined};
                    return ApiService.post(imageFindPint, data, config);
                }
            };
        }
    ]);

Im getting following error when image upload: Error: 'append' called on an object that does not implement interface FormData. jQuery.param/add

do you see I'm doing anything wrong?

3
  • This code is not using ng-file-upload. There is no service call or dependency injection. Commented Apr 1, 2016 at 15:17
  • @danial I inject the "Upload" dependancy Commented Apr 4, 2016 at 4:29
  • I don't see any code related to ng-file-upload Commented Apr 4, 2016 at 18:25

1 Answer 1

1

Pass <button type="submit" ng-click="upload('file')">submit</button>

This should solve the issue.

In the controller // file = new FormData(); // file = {'file': file};

can be removed but need to add FormData() to services.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.