0

I need to get the full file name using directive with angularjs , Bellow is my code, here I am only getting file name. Is it possible to get the full file name?

<input type="file" fileread="justice.imageLocation" />

MyApp.directive('fileread', [function(){ return { scope: { fileread:"=" }, link: function (scope, element, attributes) { element.bind("change", function (changeEvent) { scope.$apply(function () { // I am getting file name here! scope.fileread = changeEvent.target.files[0].name; }); }); } } }]);

Nikhil Nambiar
  • 376
  • 1
  • 4
  • 8

3 Answers3

0

This is actually a javascript/html question and has nothing to do with angular.

However it is simply not possible to get the path of a file client side, see this question for more information:

How to get full path of selected file on change of <input type=‘file’> using javascript, jquery-ajax?

Community
  • 1
  • 1
Rickard Staaf
  • 2,650
  • 2
  • 14
  • 14
0

I know this is old post but if someone is trying to do this in node webkit, just change .name to .path so it looks like this: changeEvent.target.files[0].path; That worked for me.

nxsm
  • 13
  • 1
  • 2
0

Try this:

function readURL(input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();

            reader.onload = function (e) {
                $('#tryy').attr('src', e.target.result);
            }

            reader.readAsDataURL(input.files[0]);
        }
    }

    $("#tryyyy").change(function(){
        readURL(this);
    });
Divyang Desai
  • 7,483
  • 13
  • 50
  • 76