【问题标题】:How to re upload the same file twice using angular-file-upload (nervgh/angular-file-upload)如何使用 angular-file-upload (nervgh/angular-file-upload) 重新上传同一文件两次
【发布时间】:2017-10-20 15:48:33
【问题描述】:

我使用 angular-file-upload 模块在我的 Angular 应用程序中上传文件,但我有要求再次上传相同的文件,但无法再次上传,因为模块在上传之前检查 item(file) 的 isUploaded 属性. 有什么解决办法吗

【问题讨论】:

  • 请向我们展示您的代码

标签: angularjs file-upload angular-file-upload


【解决方案1】:

我们可以使用onAfterAddingFile 在将文件添加到队列后触发的回调来存储原始文件的副本。现在我们可以使用uploader1uploader2分别上传原始文件和复制文件:

$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);
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-08
    • 1970-01-01
    • 2015-08-16
    • 1970-01-01
    • 2015-12-01
    • 2016-02-04
    • 2015-08-15
    相关资源
    最近更新 更多