Error on upload: response to preflight request doesn't pass access control check #493
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I'm trying to use this control in an Angular2 SPA with an ASP.NET core server-side web API.
On the server side, I'm following the example at https://www.janaks.com.np/file-upload-asp-net-core-web-api/. Essentially, my controller's code is like this:
If I test this with Postman it works as expected. Then, on the client side I have an Angular2 cli template where I did the following to install:
1.
npm install ng2-file-upload --save.2.in
app.module.tsaddimport { FileUploadModule } from 'ng2-file-upload';and addFileUploadModuleto declarations.I then used the demo's code (https://github.com/valor-software/ng2-file-upload/tree/development/demo) as the model for my component, like this (it does not seem that
FileItemis included inFileUploadModule, so I'm using ananytype):The corresponding view template is equal to that of your demo, except for the fact that I'm allowing only a single file upload:
Now, when I pick a file to upload and launch the upload, I immediately get this error from the server:
If I place a breakpoint in my upload method on server side, it never gets hit. Further, the error message looks deceiving, as I'm using CORS but I'm not allowing any wildcard. Here is my startup code for it (
Startup.cs,Configuremethod):The only relevant reference I found googling for this error message is this: https://github.com/filepicker/filepicker-js/issues/42, which was related to a bug. Could you help?
Thanks!
I found a fix at the bottom of this post: https://github.com/valor-software/ng2-file-upload/issues/399 . As a notice to this post readers,
FileItemstill remains unexported but you can just use ananytype. At least, hope this maybe useful to readers interested in an ASP.NET Core sample...