1

I am trying to send a file to the server using aurelia-fetch-client, but get the following error in the browser console. No 'Access-Control-Allow-Origin' header is present on the requested resource., but when I do the same with XMLHttpRequest file is uploaded.

Aurelia Fetch Client configuration and usage code

 activate() {
    await fetch;
    this.http = this.httpClient();


    this.http.configure(config => {
      config
        .useStandardConfiguration()
        .withBaseUrl('http://localhost:3000')
    });
}

  makeRequest(data) {
    this.http.fetch('upload', {
      headers: {
        'Content-Type': 'multipart/form-data'
      },
      method: 'post',
      body: data
    });
  }
mr. Holiday
  • 1,780
  • 2
  • 19
  • 37
  • 1
    Seems like you have not configured cors on your server? – Darxtar Oct 12 '16 at 16:06
  • Hi, i need to do the same , but cant find a solution. any updates @llia and my question is at [link](http://stackoverflow.com/questions/39991277/aurelia-js-fie-upload-to-server) – sibi Oct 13 '16 at 07:42
  • @Darxtar you were right, as I was using the node server I had to configure the cors. @sibi if you are using `express` you can use the cors-express module – mr. Holiday Oct 13 '16 at 07:51
  • @llia can u share something in git or some links to refer, since am new to this framework, am really struggling from last two days. yet, i dont have one idea. if possible answer the question from this [link](http://stackoverflow.com/questions/39991277/aurelia-js-fie-upload-to-server) – sibi Oct 13 '16 at 08:06
  • seems server team got configured cors, may problem is form view/model. can any one review the question [link](http://stackoverflow.com/questions/39991277/aurelia-js-fie-upload-to-server) – sibi Oct 13 '16 at 08:44
  • Possible duplicate of ["No 'Access-Control-Allow-Origin' header is present on the requested resource"](http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource) – Matthew James Davis Oct 19 '16 at 08:10

1 Answers1

2

Following the comments here is the answer:

CORS was not enabled on the server, and Ilia suggested the use of the cors-express module if you are using node.

The following resources can be helpful for that:

http://enable-cors.org/server_expressjs.html

https://github.com/expressjs/cors

Darxtar
  • 2,022
  • 22
  • 21
  • tnx for the reply @darxtar – sibi Oct 13 '16 at 08:41
  • seems server team got configured cors, may problem is form view/model. can any one review the question [link](http://stackoverflow.com/questions/39991277/aurelia-js-fie-upload-to-server) – sibi Oct 13 '16 at 08:44