Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

<FileInput /> doesn’t assign a button ID when files are added #159

Open
JeffreyATW opened this issue Nov 4, 2017 · 3 comments
Open

<FileInput /> doesn’t assign a button ID when files are added #159

JeffreyATW opened this issue Nov 4, 2017 · 3 comments

Comments

@JeffreyATW
Copy link

I would like to use FineUploader’s onSubmit callback to change the endpoint based on what button was used. onSubmit passes in a file ID, but I can’t use the uploader to associate it with a button because <FileInput /> doesn’t assign a button ID to the file when it’s added.

Would it be possible to assign a unique button ID to each <FileInput /> instance?

@rnicholus
Copy link
Member

I think there will need to be something exposed in the API to allow an input device (such as a button) with the submitted files. One way to do this is by adding another optional param to the addFiles API method and then yet another method to retrieve the ID given a blob ID. And then of course React Fine Uploader will need to be updated to pass this value, if it exists, to addFiles. Probably just easier in your case to use a unique Uploader instance per button.

@rnicholus
Copy link
Member

Another option: create your own wrapper for a file input element (should be pretty easy) and track the selected files. Test each submitted file against your tracked files to find the relevant button. Or PR to modify the FileInput component to allow these selected files to be exposed for this purpose.

Still another idea is for FileInput to append a property to each selected File object matching some ID passed to FileInput as a param. Then, in onSubmit, call getFile and check this prop. That is probably the simplest solution.

@JeffreyATW
Copy link
Author

I think the FileInput should replicate what happens within the _onInputChange method. Prior to adding files, it annotates the file with the current button ID. (The button ID is generated here.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants