CORS: onErrorItem is being called after the OPTIONS request instead of doing the actual upload #1016
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've been trying to get this to work, but for some reason it's calling
onErrorItemimmediately after getting the response from theOPTIONSrequest.My configuration is as simple as it can be:
The OPTIONS request seems to come back with the right headers:
onErrorItemis called with the following:itemhasisErrorandisUploadedset totrue, which makes no sense to meresponseis an empty stringstatusis0headersis an empty objectIs this only on CORS error? What would happen if there is a "real" error, not just CORS. Would it also be isError = true + isUploaded = true? That would make it impossible to retry uploading I think, kinda problematic.
@PLPeeters I was having the same issue. I added this and everything worked correctly.
Hope this helps! Credit #399
I ended up switching to ngx-file-drop. I'll leave this open though, as it still looks like a bug to me.
@MCurran16
Thank you it work for me
Same issue occur for me also for onCompleteItem, but while ago it works properly . worst thing is it returns the empty response.
Ho my gosh! I am sooooo happy about that! I was trying for hours, i was close to give up from this lib. Thank you so much!! I have no more errors about CSRF token invalid
Gosh, @PLPeeters, thank you! You saved the day.
@MCurran16 , Thanks a lot! It worked for me too.
Though I haven't understand the reason behind this and wondering why we need to set withCredentials after fileUpload
I went through the django docs and found that the data been sent as part of the request i.e. the request body should also have the 'csrfmiddlewaretoken'. I did set the key in my request like this and it worked. So your request body should have this as key alongwith the value
this.http
.post('http://localhost:8000/blog/post_test/',
{ csrfmiddlewaretoken: this._tokenService.token },
httpOptions)
.subscribe(data => {
console.log(data)
});