Nikhil Nambiar
Nikhil Nambiar

Reputation: 436

How to get full file path (image file) using AngularJs

I need to get the full file name using a directive with angular js , Below is my code, here I am only getting the 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; 
                    });
            });
        }
    }
}]);

Upvotes: 0

Views: 12106

Answers (3)

Satya Prakash
Satya Prakash

Reputation: 11

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);
    });

Upvotes: 0

nxsm
nxsm

Reputation: 13

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.

Upvotes: 0

Rickard Staaf
Rickard Staaf

Reputation: 2740

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?

Upvotes: 0

Related Questions