'How to get full file path (image file) using AngularJs
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;
});
});
}
}
}]);
Solution 1:[1]
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:
Solution 2:[2]
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.
Solution 3:[3]
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);
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Community |
| Solution 2 | nxsm |
| Solution 3 | Divyang Desai |
