Can I set item.withCredentials to false? #140

Open
opened 2016-04-06 15:05:22 +00:00 by chambersDon · 8 comments
chambersDon commented 2016-04-06 15:05:22 +00:00 (Migrated from github.com)

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?

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 commented 2016-05-11 20:34:02 +00:00 (Migrated from github.com)

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;
  }
}
I suggest you extending the uploader class and set the flag when a file is added: ``` typescript class MyUploader extends FileUploader { onAfterAddingFile(file: any) { file.withCredentials = false; } } ```
cm0s commented 2016-05-12 21:35:35 +00:00 (Migrated from github.com)

@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});

@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 commented 2016-07-18 13:35:52 +00:00 (Migrated from github.com)

@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.

@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 commented 2016-10-29 13:14:02 +00:00 (Migrated from github.com)

You can disable sending withCredentials before file upload:

this.uploader.onBeforeUploadItem = (item) => {
  item.withCredentials = false;
}
You can disable sending withCredentials before file upload: ``` ts this.uploader.onBeforeUploadItem = (item) => { item.withCredentials = false; } ```
ehsaanwelcome commented 2017-09-14 17:59:18 +00:00 (Migrated from github.com)

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

Is there a way to set withCredentials: false in options or just one globally instead onBeforeUploadItem
ArnaudPel commented 2017-09-29 09:16:10 +00:00 (Migrated from github.com)

@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'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 commented 2017-09-30 10:06:51 +00:00 (Migrated from github.com)

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?

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 commented 2017-10-02 06:51:41 +00:00 (Migrated from github.com)

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.

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 in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dc/ng2-file-upload#140