Abhi
Abhi

Reputation: 1574

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

Upvotes: 3

Views: 22618

Answers (2)

xkeshav
xkeshav

Reputation: 54022

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>

Upvotes: 3

Sajeetharan
Sajeetharan

Reputation: 222582

You can access like this,

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

Upvotes: 3

Related Questions