How to get the filename of the uploaded file in ng-file-upload
21,737
Solution 1
You can access like this,
$scope.filename = $scope.file.name;
Solution 2
try this with ng-bind
<button type="button" ngf-select ng-model="formdata.file" name="file">Select</button>
<div ng-bind="formdata.file.name"></div>
Comments
-
Abhi over 3 years
I am using angularjs and the ng-file-upload to upload a file to a server. I want to get the file name so that I can save it with the same name in the server.
After uploading I see the file name near the "choose file" button, but I want to set the file name to a scope variable so that I can pass the file name to server along with the file.
The upload code:
Upload.upload({ url: $scope.ipForHttp+"addVehicles?ClassificationID=" + $scope.C.ClassificationID + "&ClassName=" + $scope.C.ClassName + "&ClassRate=" + $scope.C.ClassRate + "&ClassImage="+$scope.file+"&ClientID=1", data:{file:$scope.file} })
The html:
<input type="file" ngf-select ng-model="file" name="file" ngf-pattern="'image/*'"accept="image/*" ngf-max-size="20MB" />