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

xhrUploader settings function cannot set authorization header because request not open #71

Closed
zekenie opened this issue Jan 24, 2020 · 0 comments
Labels
bug Something isn't working

Comments

@zekenie
Copy link
Contributor

zekenie commented Jan 24, 2020

Version: 2
I'm trying to upload to an API that requires an authorization header, similar to the strategy referenced in the documentation.

I define my uppload object like this:

const uppload = new Uppload({
  lang: en,
  defaultService: "local",
  uploader: xhrUploader({
    endpoint: `${process.env.API_URL}/attachments`,
    settingsFunction(xmlHttp) {
      xmlHttp.setRequestHeader("authorization", Auth.getToken());
    }
  })
});

I get the following error:

Failed to execute 'setRequestHeader' on 'XMLHttpRequest': The object's state must be OPENED.

When I look at the code for the xhrUploader, it seems like the settingsFunction is called after the XMLHttpRequest is instantiated but before it is opened. Since the request is not open, I cannot set my header.

AnandChowdhary added a commit that referenced this issue Jan 25, 2020
Fixes #71 XHR calls settings function after request open
@AnandChowdhary AnandChowdhary added the bug Something isn't working label Jan 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants