{"action":"created","issue":{"url":"https://api.github.com/repos/valor-software/ng2-file-upload/issues/573","repository_url":"https://api.github.com/repos/valor-software/ng2-file-upload","labels_url":"https://api.github.com/repos/valor-software/ng2-file-upload/issues/573/labels{/name}","comments_url":"https://api.github.com/repos/valor-software/ng2-file-upload/issues/573/comments","events_url":"https://api.github.com/repos/valor-software/ng2-file-upload/issues/573/events","html_url":"https://github.com/valor-software/ng2-file-upload/issues/573","id":201190652,"number":573,"title":"XMLHttpRequest cannot load http://localhost/some-url. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.","user":{"login":"saumya04","id":4142868,"avatar_url":"https://avatars2.githubusercontent.com/u/4142868?v=3","gravatar_id":"","url":"https://api.github.com/users/saumya04","html_url":"https://github.com/saumya04","followers_url":"https://api.github.com/users/saumya04/followers","following_url":"https://api.github.com/users/saumya04/following{/other_user}","gists_url":"https://api.github.com/users/saumya04/gists{/gist_id}","starred_url":"https://api.github.com/users/saumya04/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saumya04/subscriptions","organizations_url":"https://api.github.com/users/saumya04/orgs","repos_url":"https://api.github.com/users/saumya04/repos","events_url":"https://api.github.com/users/saumya04/events{/privacy}","received_events_url":"https://api.github.com/users/saumya04/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-01-17T06:56:14Z","updated_at":"2017-05-05T15:58:08Z","closed_at":null,"body":"I am experiencing this issue in all browsers.\r\n```\r\nXMLHttpRequest cannot load http://localhost/some-url.\r\nResponse to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.\r\nOrigin 'http://localhost:4200' is therefore not allowed access.\r\n```\r\n\r\nThe Request headers sent are:\r\n![screen shot 2017-01-17 at 12 19 05 pm](https://cloud.githubusercontent.com/assets/4142868/22010453/54891d72-dcaf-11e6-9b0a-6ace08350a73.png)\r\n\r\nI'm initiating the file uploader as\r\n```\r\nthis.profilePicUploader = new FileUploader({\r\n  url: 'some-url',\r\n  method: 'POST',\r\n  authToken: 'some-auth-token',\r\n  headers: [\r\n    {\r\n      name: 'api-secret',\r\n      value: 'some-api-secret-key'\r\n    },\r\n    {\r\n      name: 'auth-token',\r\n      value: 'some-auth-token'\r\n    }\r\n  ],\r\n  queueLimit: 1,\r\n});\r\n```\r\n\r\nI've over-ridden the `onAfterAddingFile` option as: \r\n```\r\nthis.profilePicUploader.onAfterAddingFile = (fileItem: any) => {\r\n  fileItem.withCredentials = false;\r\n}\r\n```\r\n\r\nCan you please help me regarding this. I am using [Laravel](http://laravel.com/) as my back-end. For enabling CORS in my backend I've used [Laravel CORS plugin](https://github.com/barryvdh/laravel-cors) on the server."},"comment":{"url":"https://api.github.com/repos/valor-software/ng2-file-upload/issues/comments/299504051","html_url":"https://github.com/valor-software/ng2-file-upload/issues/573#issuecomment-299504051","issue_url":"https://api.github.com/repos/valor-software/ng2-file-upload/issues/573","id":299504051,"user":{"login":"pterrajkumar","id":10940968,"avatar_url":"https://avatars1.githubusercontent.com/u/10940968?v=3","gravatar_id":"","url":"https://api.github.com/users/pterrajkumar","html_url":"https://github.com/pterrajkumar","followers_url":"https://api.github.com/users/pterrajkumar/followers","following_url":"https://api.github.com/users/pterrajkumar/following{/other_user}","gists_url":"https://api.github.com/users/pterrajkumar/gists{/gist_id}","starred_url":"https://api.github.com/users/pterrajkumar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pterrajkumar/subscriptions","organizations_url":"https://api.github.com/users/pterrajkumar/orgs","repos_url":"https://api.github.com/users/pterrajkumar/repos","events_url":"https://api.github.com/users/pterrajkumar/events{/privacy}","received_events_url":"https://api.github.com/users/pterrajkumar/received_events","type":"User","site_admin":false},"created_at":"2017-05-05T15:58:08Z","updated_at":"2017-05-05T15:58:08Z","body":"\r\nIn AspNetCore web api, this issue got fixed by adding \"Microsoft.AspNetCore.Cors\" (ver 1.1.1) and adding the below changes on Startup.cs.\r\n\r\npublic void ConfigureServices(IServiceCollection services) {\r\n\r\nservices.AddCors(options =>\r\n{\r\n      options.AddPolicy(\"AllowAllHeaders\",\r\n            builder =>\r\n        {\r\n                builder.AllowAnyOrigin()\r\n                       .AllowAnyHeader()\r\n                       .AllowAnyMethod();\r\n            });\r\n});\r\n.\r\n.\r\n.\r\n}\r\n\r\nand\r\n\r\npublic void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) {\r\n\r\n// Shows UseCors with named policy.\r\napp.UseCors(\"AllowAllHeaders\");\r\n.\r\n.\r\n.\r\n}\r\n\r\nand putting [EnableCors(\"AllowAllHeaders\")] on the controller."}}
{"actor":{"display_login":"pterrajkumar"}}