I’m uploading a file to a directory using a Web Service in Angular Js by using the module ‘FileUploader’. When i click on the button upload, the file is uploaded to the directory. When I upload a file again and the click on the button upload, the file is not uploaded. It seems like it is not being reset.
This is the code in my controller :
var uploader = vm.uploader = new FileUploader({
url: WS link,
alias: 'file'
});
// FILTERS
// a sync filter
uploader.filters.push({
name: 'syncFilter',
fn: function (item, options) {
return this.queue.length < 10;
}
});
// an async filter
uploader.filters.push({
name: 'asyncFilter',
fn: function (item, options, deferred) {
setTimeout(deferred.resolve, 1e3);
}
});
// CALLBACKS
uploader.onBeforeUploadItem = function (item) {
};
uploader.onCompleteItem = function (fileItem, response, status, headers) {
if (status != 200) {
vm.enableMsg = true;
} else {
$scope.attachmentId = response.File;
alertService.success("Fichier uploadé");
vm.fileSelect = '';
vm.enableMsg = true;
}
};
uploader.onCompleteAll = function () {
};
This is the html page containing the button upload, making the call to the Fileuploader module. The name of the controller is test.
<input type="file" nv-file-select="test.fileSelect" uploader="test.uploader">
<a ng-click="test.uploader.uploadAll()"><span class="fa fa-upload"></span></a>
Source: AngularJS
from Angular Questions https://angularquestions.com/2017/10/20/upload-file-to-a-directory-using-angularjs-fileuploader/
via @lzomedia #developer #freelance #web #lzomedia.com
No comments:
Post a Comment