iLiveInAPineappleUnderTheSea iLiveInAPineappleUnderTheSea - 2 months ago 11
AngularJS Question

How to get the filename of the uploaded file in ng-file-upload

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" />

Answer

You can access like this,

   $scope.filename = $scope.file.name;
Comments