I'm trying to create an image upload feature for a user profile update part of an Ionic/Angular application. The upload feature is part of the form and I am unable to retrieve the image and the filename. How would I get both items? Below is my code:
Form (View):
<div class="item-input">
<!--list item-->
<div data-ng-repeat="user in users">
Username: <input type="text" placeholder="Enter the event name" name="username" ng-model="user.username" required>
Password: <input type="password" placeholder="Enter the password" name="password" ng-model="user.password" required>
Email: <input type="text" placeholder="Enter the email" name="email" ng-model="user.email" required>
Hometown: <input type="text" placeholder="Enter your hometown" name="hometown" ng-model="user.hometown" required>
Firstname: <input type="text" name="firstname" ng-model="user.firstname" required>
Lastname: <input type="text" name="lastname" ng-model="user.lastname" required>
Birthday: <date-picker ng-model="user.birthday"></date-picker>
Image: <input type="file" name="file" ng-model="filename">
<button ng-click="upload(file)">Upload</button>
<button class="button button-block button-positive" ng-click="editprofile(user)">
Edit Account
</button>
<button class="button button-block button-positive" ng-click="deleteprofile()">
Delete Account
</button>
</div>
Controller
.controller('ProfileUpdateCtrl', function($http, $state, $http, $cordovaOauth, $stateParams, $rootScope, $scope, UserFac) {
//removed the working features to focus on the uploading part.
$scope.upload = function(file) {
var filename = $scope.file.name;
//need to know how to get the data of the image and save as formdata
}
});