ng2-file-upload icon indicating copy to clipboard operation
ng2-file-upload copied to clipboard

Multiple uploaders on a single page...

Open derailed opened this issue 8 years ago • 11 comments

Hi,

I am trying to use your nice lib to get multiple uploaders on a single page. Each uploader resolve to a different backend server url. Say I have uploader1 with url set to /loader1 and uploader2 with url set to /loader2. No matter what I've tried. it seems that the second file input (uploader2) is somehow binding to uploader1. Ie using your demo table to show the files to be uploaded, always appear on the first loader but not the second. Doing the actual upload the files destined for uploader2 end up being uploaded on /loader1 url. What am I missing?

Thank you!

derailed avatar Aug 17 '17 21:08 derailed

Having the same issue. Did you manage to resolve this?

EduardsE avatar Sep 06 '17 09:09 EduardsE

Can you provide some sample code to reproduce this problem ?

adrianfaciu avatar Oct 01 '17 10:10 adrianfaciu

I am facing the same issue. I think it's connected to the ng2FileSelect directive. If you have multiple uploaders on the same page, only one will be targeted when selecting a file. The temporary solution for me is to only use drag and drop, but that's really inconvenient.

Shiroh1ge avatar Nov 01 '17 13:11 Shiroh1ge

I'm Having the same problem. Multiple ng2FileSelect directives, defined to upload to different paths, But only one is being use, regardless of which one is being clicked. !!

In my case the directives are actually defined in different components, and those components are available as sub components on the same page.

Any solution to this?

rsaf avatar Dec 06 '17 05:12 rsaf

@rsaf To make it work, I added a custom ID to each input and corresponding label.

<input type="file" name="file" id="{{ 'file' + iterator}}" #fileInput ng2FileSelect [uploader]="uploader" class="inputfile"/> <label for="{{ 'file' + iterator}}">Choose a file</label>

EduardsE avatar Dec 06 '17 07:12 EduardsE

@EduardsE Thank you so much.

I got it working.

The problem was indeed the id field. I was using the same ID for different file inputs. I didn't pay attention to that because I was using each file input on a different component.

I think the documentation needs to emphasize that it's using the ID field to find the uploader! Which seems to be a major issue.

rsaf avatar Dec 07 '17 03:12 rsaf

Two different ids are used for the two different file input. However, the size of the selected file size is always zero for the second file input. The following are the two input type.

<input type="file" accept="image/*" style="display:none" id="contentUpload" ng2FileSelect [uploader]="contentUploader" (change)="OnContentChange($event)">

<input type="file" multiple accept="image/*" style="display:none" id="styleUpload" ng2FileSelect [uploader]="styleUploader" (change)="OnStyleChange($event)">

cylof22 avatar Mar 20 '18 08:03 cylof22

@cylof22 Does it work without the "multiple" attribute?

EduardsE avatar Mar 20 '18 11:03 EduardsE

@EduardsE Removing the "multiple" will fix the problem. Thanks for your answer. However, I think this is bug.

cylof22 avatar Mar 20 '18 12:03 cylof22

How to get the ID of the uploader in the event like OnAfterAddingFile? I am wondering how to know which file is uploaded by which uploader if there are more than one uploader in single page?

NeelBhatt avatar Sep 27 '18 13:09 NeelBhatt

Have separate uploader variable for each of your uploaders. Eg. imageUploader, videoUploader. @NeelBhatt. Have separate listeners for each of these. Also have separate id to tell the DOM to distinguish the inputs.

vishnu-dev avatar Jan 10 '20 06:01 vishnu-dev