Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,

I am trying to upload the file using angularjs but i am not getting the full filepath while uploading.

How can i get the full file path when uploading the path.

I am sharing my code below:-

What I have tried:

<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script>
debugger;
var myApp = angular.module('fupApp', []);

myApp.controller('fupController', function ($scope) {
debugger;
//GET THE FILE INFORMATION.
$scope.getFileDetails = function (e) {
//debugger;
var filename = document.getElementById("file").value;
$scope.files = [];
$scope.$apply(function () {
debugger;
// STORE THE FILE OBJECT IN AN ARRAY.
for (var i = 0; i < e.files.length; i++) {
$scope.files.push(e.files[i])
}

});
};

$scope.uploadFiles = function () {
debugger;
//FILL FormData WITH FILE DETAILS.
var data = new FormData();

for (var i in $scope.files) {
// data.append("uploadedFile", $scope.files[i]);
}

debugger;
var fileName = $scope.files[0];//here i am getting only filename and filesize .

//alert($scope.filename);





}

// UPDATE PROGRESS BAR.
function updateProgress(e) {
if (e.lengthComputable) {
document.getElementById('pro').setAttribute('value', e.loaded);
document.getElementById('pro').setAttribute('max', e.total);
}
}

// CONFIRMATION.
function transferComplete(e) {
alert("Files uploaded successfully.");
}
});
</script>
</head>
<body ng-app="fupApp">

<div ng-controller="fupController">
<input type="file" id="file" name="file" multiple
onchange="angular.element(this).scope().getFileDetails(this)" />

<input type="button" ng-click="uploadFiles()" value="Upload" />

<!--ADD A PROGRESS BAR ELEMENT.-->
<p><progress id="pro" value="0"></progress></p>
</div>

</body>
</html>
Posted
Updated 24-Jan-17 4:36am
v2
Comments
Nathan Minier 24-Jan-17 8:04am    
Why would you not just do this:
<input type="file" ng-model="files" multiple />
ZurdoDev 24-Jan-17 10:55am    
Why do you want the full file path?
dattaprasaddhuri 24-Jan-17 12:01pm    
I want to pass that path to my activex control to perform some operations and want to save at another location.
ZurdoDev 24-Jan-17 12:02pm    
The fileuploader control is designed to save on the server, not the client.

1 solution

You cannot get the full path for two reasons:
1) It is prevented by the browser for security reasons.
and
2) It's of no relevance to the Server since it can't access the path on a client machine anyway - again for security reasons.

And remember: not every device which can talk to the internet has a concept of paths: this could be an internet connected fridge for all you know!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900