Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p-fileupload onBeforeSend not working properly. #7741

Closed
ipuiu opened this issue May 28, 2019 · 3 comments
Closed

p-fileupload onBeforeSend not working properly. #7741

ipuiu opened this issue May 28, 2019 · 3 comments

Comments

@ipuiu
Copy link
Contributor

ipuiu commented May 28, 2019

I'm submitting a ...

[x] bug report 

Plunkr Case (Bug Reports)

https://stackblitz.com/edit/github-8qbdgu

Current behavior
onBeforeSend event of p-fileupload has no xhr object to add headers.

Expected behavior
onBeforeSend event of p-fileupload has should have a xhr object to add headers, as the documentation states in it's event definition: "Callback to invoke before file send begins to customize the request such as adding headers.".

What is the motivation / use case for changing the behavior?
I need to add a custom header on the upload request.

  • Browser: [all]

  • Language: [all]

@JacobSiegle
Copy link
Contributor

onBeforeSend seems bugged further then just the headers not being exposed. The comment on the function that emits onBeforeSend says The request was sent out over the wire. so you cannot customize the header or formData on it because the web request has already been sent.

Using onBeforeUpload seems to allow you to customize the formData but doesn't expose customizing headers.

To expose the headers you need to make the header a generic object since using Angulars HttpHeader object doesn't update the reference emitted when calling append (it creates a new header obj).

            let headers = {};
            this.onBeforeUpload.emit({
                'formData': formData,
                'headers': headers
            });

            for(let i = 0; i < this.files.length; i++) {
                formData.append(this.name, this.files[i], this.files[i].name);
            }

            this.http.post(this.url, formData, {
                reportProgress: true,
                observe: 'events',
                headers: headers
            }).subscribe( (event: HttpEvent<any>) => {

I can PR it if I get time, otherwise anyone else feel free to. Maybe emitting an entire RequestOptions obj instead of headers would fix the reference issue mentioned before.

@cagataycivici cagataycivici self-assigned this Jun 3, 2019
@cagataycivici cagataycivici added the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Jun 3, 2019
@cagataycivici cagataycivici added this to the 8.0.0 milestone Jun 3, 2019
@cagataycivici cagataycivici removed this from the 8.0.0 milestone Jun 13, 2019
@cagataycivici cagataycivici removed the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Jun 13, 2019
@cagataycivici cagataycivici removed their assignment Jun 13, 2019
@cagataycivici
Copy link
Member

See;

#7805
#7803

@JacobSiegle
Copy link
Contributor

Closed PR.

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

No branches or pull requests

3 participants