0

I am using a directive to upload the files, its uploading the files correctly, But its not uploading the file content. How to upload the file with file content.

form.directive('ngFileModel', ['$parse', function ($parse) {
    return {
        restrict: 'A',
        link: function (scope, element, attrs) {
            var model = $parse(attrs.ngFileModel);
            var isMultiple = attrs.multiple;
            var modelSetter = model.assign;
            element.bind('change', function () {
                var values = [];
                angular.forEach(element[0].files, function (item) {
                    var value = {
                       // File Name 
                        name: item.name,
                        //File Size 
                        size: item.size,
                        //File URL to view 
                        url: URL.createObjectURL(item),
                        // File Input Value 
                        _file: item
                    };
                    values.push(value);
                });
                scope.$apply(function () {
                    if (isMultiple) {
                        modelSetter(scope, values);
                    } else {
                        modelSetter(scope, values[0]);
                    }
                });
            });
        }
    };
}]);
georgeawg
  • 48,608
  • 13
  • 72
  • 95
YYY
  • 3,440
  • 5
  • 20
  • 24
  • What you mean `content`? – Saeed Apr 30 '18 at 07:39
  • Hi Saeed, thanks for the reply, Content means the data of the file. I want to create a blob object to read the file data. – YYY Apr 30 '18 at 11:32
  • Did you test my answer?! You can pass any object with your specific keys to server. Is that irrelevant? @arjun – Saeed Apr 30 '18 at 11:36

0 Answers0