html
<form method='POST' enctype='multipart/form-data' name="formName">
<div class="row">
<div class="col-md-6">
<input type="file" style="text-align: left" ng-model="value" class="btn"/>
</div>
<div class="col-md-2">
<input type="submit" value="upload" class="btn btn-info" ng-click="submitFile()"/>
</div>
</div>
</form>
AngularJs
$scope.submitFile = function(){
document.formName.action = 'http://xxx.xxx.xxx.xxx:8000/ww/up?s=' + $rootScope.reply.Sid; //$rootScope.reply.Sid is secession id
document.formName.submit();
};
I am trying to do a fileupload with AngularJs. Will this logic work?. My selected path is also coming as given below.
C:\fakepath\license.txt
Note: Our UI team was able to the fileupload with the below code. I was trying to attain the same thing in AngularJs
<body>
<form method='POST' enctype='multipart/form-data' action="http://xxx.xxx.xx.xxx:xxxx/yyy/yyyyyyyyy?s=3e3646ea-48cc-4342-a388-e0c0d7bbf4e4"/'>
File to upload: <input type=file id='up_file' name=upfile><br>
</body>
You did it right .. you only have to change few things to make it work
Change
<form method='POST' enctype='multipart/form-data' name="formName">
To
<form action="{{action}}" method='POST' enctype='multipart/form-data' name="formName">
In controller inject $timeout along with $scope
app.controller('Test', function($scope, $rootScope, $timeout){
$scope.submitFile = function(){
$scope.action = 'http://xxx.xxx.xxx.xxx:8000/ww/up?s=' + $rootScope.reply.Sid;
$timeout(function(){
document.formName.submit();
}, 100);
}
});
Action assigning $scope.action with new data .. angularjs needs to update the dom .. that is the reason we are using $timeout and submitting the form
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With