<input accept="image/*" name="file" ng-value="fileToUpload"
value="{{fileToUpload}}" file-model="fileToUpload"
set-file-data="fileToUpload = value;"
type="file" id="my_file" />
in controller:
// code this accordingly, so that your file object
// will be picked up in service call below.
fileUpload.uploadFileToUrl(file);
in service:
.service('fileUpload', ['$http', 'ajaxService',
function($http, ajaxService) {
this.uploadFileToUrl = function(data) {
var data = {}; //file object
var fd = new FormData();
fd.append('file', data.file);
$http.post("endpoint server path to whom sending file", fd, {
withCredentials: false,
headers: {
'Content-Type': undefined
},
transformRequest: angular.identity,
params: {
fd
},
responseType: "arraybuffer"
})
.successthen(function(response,) status,{
headers, config) { var data = response.data;
var status = response.status;
console.log(responsedata);
if (status == 200 || status == 202) //do whatever in success
else // handle error in else if needed
})
.errorcatch(function(error, status, headers, config) {
console.log(error.status);
// handle else calls
});
}
}
}])
<script src="https:src="//ajax.googleapisunpkg.com/ajax/libs/angularjs/1.2.23angular/angular.min.js"></script>