Reputation: 49
I want to input an image and upload it to a folder on my local machine.
HTML :
<md-input-container class="md-block" flex-gt-sm>
<h4>Image</h4>
<input type="file" ng-model="post.primaryImage" />
</md-input-container>
CONTROLLER :
var url = '/Users/my.name/Desktop/images'
$scope.OnSubmit = function() {
//ResourceService.addMachine.save($scope.post);
console.log( $scope.post );
$scope.upload(file);
}
$scope.upload = function (file) {
Upload.upload({
url: 'url',
data: {file: file}
}).then(function (resp) {
console.log('Success ' + resp.data);
});
}
Infact the image is not getting input . When i print scope.post a blank object is printed on the console. I have read several answers on the topic , but there isn't any answered question on how to upload the image on the local system's folder.
Upvotes: 1
Views: 2572
Reputation: 4370
Try using ngf-select
like this :
HTML
<div ng-controller="MyCtrl">
<input type="file" ngf-select="onFileSelect($files)" multiple>
</div>
Controller
angular.module('myApp', ['ngFileUpload']);
var MyCtrl = ['$scope', 'Upload', function($scope, Upload) {
$scope.onFileSelect = function($files) {
for (var i = 0; i < $files.length; i++) {
var $file = $files[i];
Upload.upload({
url: 'my/upload/url',
file: $file,
})
}
}
}];
Here is the jsFiddle
Hope it works :)
Upvotes: 1