0

how to upload an image and send to server

this is my directive

angular.module('vistalyticsApp').
    directive('onReadFile', function ($parse) {
    return {
        restrict: 'A',
        scope: false,
        link: function(scope, element, attrs) {
            var fn = $parse(attrs.onReadFile);

            element.on('change', function(onChangeEvent) {
                var reader = new FileReader();

                reader.onload = function(onLoadEvent) {
                    scope.$apply(function() {
                        fn(scope, {$fileContent:onLoadEvent.target.result,$fileName:onChangeEvent.target.files[0].name});
                    });
                };

                reader.readAsText((onChangeEvent.srcElement || onChangeEvent.target).files[0]);
            });
        }
    };
});

how to upload an image and send to server

mbojko
  • 13,503
  • 1
  • 16
  • 26
sowmya
  • 79
  • 8

0 Answers0