Re-select the same file doesn't work #871
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hello,
I noticed that when selecting a file, then I remove it, then I try to select the same file, I am not able to do it.
In my case I am using the Single file select. My app is Angular 4.
Any idea how to change this behavior?
Thanks
I am experiencing the same type of issue. Selecting a file uploaded during a single control initialization does not seem to work. One can select other files, but any file uploaded can't be added again until the component is reinitialized.
This behavior can be reproduced on the test webpage for the library http://valor-software.com/ng2-file-upload/, just select the same file two times in a row during an upload operation. Even after removing the file from the queue the file does not get added and the "Upload All" button remains disabled.
In my own experience, this is the typical behavior of an HTML input tag. I've seen this issue on other websites that don't make use of ng2-file-upload. The input tag holds the previous value, and only kicks off an upload when that value changes. Selecting the same value again doesn't upload the file a second time. Here's my workaround:
@benjcallaghan It works for me! But I write it code in the upload success callback function, like this.
This is more related to the input tag, but if you want to add some functionality to ng2-file-upload to natively handle this, a pull request would be more than welcome 😉
I use this,
Because success and failure will be working
this.uploader.onCompleteAll = () => { this.fileInput.nativeElement.value = ''; }public onChange($event: any): void {
let target = $event.target || $event.srcElement;
this.fileUploadService.addToQueue(target.files);
target.value = '';
}
WORK FOR ME
you need to empty the input file value after upload
here the code worked for me
HTML:
<input type="file" name="myfile" #activeFrameinputFile ng2FileSelect [uploader]="frameUploader" (change)="frameUploader.uploadAll()" />component
import { Component, OnInit, ElementRef, ViewChild } from '@angular/core';@ViewChild('activeFrameinputFile') InputFrameVariable: ElementRef;this.frameUploader.onSuccessItem = (item, response, status, headers) => {this.InputFrameVariable.nativeElement.value = '';};this will definitely works
if (this.selectedFiles.length === 0) { this.epubFileUploader.nativeElement.value = ''} worked for me..