Skip to content

Can I set item.withCredentials to false? #140

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

Open
chambersDon opened this issue Apr 6, 2016 · 8 comments
Open

Can I set item.withCredentials to false? #140

chambersDon opened this issue Apr 6, 2016 · 8 comments

Comments

@chambersDon
Copy link

I have been having a problem with the post. When I click 'upload all' the progress bar moves but it never actually posts the file. I don't see any errors.

I stumbled across the problem on line 329 of file-uploader.ts.
xhr.withCredentials = item.withCredentials;

If I change this to xhr.withCredentials = false; it will work.

Is there a way to set this as a property from outside?

I am setting the authToken. When withCredentials is false I get the post on the server side and it is authenticated. My angular2 client is a different site than the webApi it calls. CORS is setup and I am getting the post when withCredential is false.
I'm not really sure what this is doing but I know if has something to do with cross-site scripting.

Can I set it to false from outside?
Is that the proper fix?

@JulioC
Copy link

JulioC commented May 11, 2016

I suggest you extending the uploader class and set the flag when a file is added:

class MyUploader extends FileUploader {
  onAfterAddingFile(file: any) {
    file.withCredentials = false;
  }
}

@cm0s
Copy link

cm0s commented May 12, 2016

@chambersDon you should probably add your server domain address to your Access-Control-Allow-Origin header. I assume it's either not set or set with the wild card : *. Which is not authorized if you don't set the credentials to false in the XHR option (withCredentials = false).

@JulioC I also need to change the credentials option. Extending the class works but it could be great to add a withCredential option at the FileUploader constructor level, like this :
new FileUploader({url: 'http://server/api', withCredentials: false});

@wezzcoetzee
Copy link

@cm0s - could you possibly provide the code to extend the class? I've been trying for a few hours and can't seem to get it to work.

@neilhem
Copy link

neilhem commented Oct 29, 2016

You can disable sending withCredentials before file upload:

this.uploader.onBeforeUploadItem = (item) => {
  item.withCredentials = false;
}

@ehsaanwelcome
Copy link

ehsaanwelcome commented Sep 14, 2017

Is there a way to set withCredentials: false in options or just one globally instead onBeforeUploadItem

@ArnaudPel
Copy link

@neilhem's answer just saved my day. All I could figure out before reaching this post by sheer Google power was that my uploader was only sending an OPTIONS request and nothing else... Hard to fix.

Since this ticket is still open, may I suggest logging some sort of warning to let the dev know why nothing is beeing uploaded ? Many thanks.

@neilhem
Copy link

neilhem commented Sep 30, 2017

Yeah, this is sad that we need so many time to figure out way disabling some options. @valorkin can we suggest PR to add a line into docs?

@ArnaudPel
Copy link

Docs is always good yes, but if it's acceptable in that case I think logging some hints in the console would help a lot. I usually search the documentation based on what I understand of the problem, and in that case, there was literally no clue.

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

No branches or pull requests

8 participants