How to re upload the same file twice using angular-file-upload (nervgh/angular-file-upload)

Issue

im using angular-file-upload module for uploading files in my angular application , but i have requirement like upload the same file again , but not able to upload again , as module checks the isUploaded property of item(file) before uploading .
is there any work around

Solution

We can use the onAfterAddingFile call back which is getting fired after adding a file to queue, to store the copy of the original file. now we can upload the original and copied file separately using uploader1 and uploader2:

$scope.uploader1 = new FileUploader({
    url: url,
    queueLimit: 1
});

$scope.uploader2 = new FileUploader({
    url: url,
    queueLimit: 1
});

uploader1.onAfterAddingFile = function (fileItem1) {                                          
    var fileItem2 = new FileUploader.FileItem($scope.uploaderOnSuccess, 
    {
        lastModifiedDate: fileItem1.file.lastModifiedDate,
        size: fileItem1.file.size,
        type: fileItem1.file.type,
        name: fileItem1.file.name,
    });
    fileItem2._file = fileItem1._file;               
    fileItem2.progress = 0;
    fileItem2.isUploaded = false;
    fileItem2.isSuccess = false;
    $scope.uploader2.queue.push(fileItem2);
};

Answered By – Dhanesh H S

Answer Checked By – Senaida (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.