fileupload onBeforeUpload should be fired before appending files to FormData #1489

Merged
merged 1 commit into from Dec 7, 2016

Projects

None yet

4 participants

@radarsu
Contributor
radarsu commented Dec 2, 2016

Issue #1332

In documentation onBeforeUpload event is described:
Callback to invoke before file upload begins to customize the request such as adding header and post parameters.

But some frameworks require post parameters to be appended to FormData before files.

When onBeforeUpload event emits xhr and FormData, there is no way to "prepend" any data to FormData object, so some backend frameworks will return errors like this:
Unable to expose body parameter `exampleParameter` in streaming upload! Client tried to send a text parameter (exampleParameter) after one or more files had already been sent. Make sure you always send text params first, then your files. (In an HTML form, it's as easy as making sure your text inputs are listed before your file inputs.

@cagataycivici cagataycivici added this to the 1.0.2 milestone Dec 7, 2016
@cagataycivici cagataycivici self-assigned this Dec 7, 2016
@cagataycivici cagataycivici merged commit 55ab75a into primefaces:master Dec 7, 2016
@robkrause

This way I can't call setRequestHeader() anymore since it has to be done after xhr.open()

@MarkWilds
Contributor

uhm I think they should split this up in two events because now I can't call setRequestHeader() anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment