Closed elliottpalermo closed 4 years ago
I think the formdata just needs to override the default impl of toString. There was a similar bug logged on the XMLHttpRequest polyfill.
Hello! Thanks for taking a look.
It actually looks like it already does override/implement toString here, https://github.com/oracle/cordova-plugin-wkwebview-file-xhr/blob/master/src/www/ios/formdata-polyfill.js#L197
That’s why calling (new FormData()).toString() will correctly return “[object FormData]”
The problem comes when using Object.toString.call (or apply, etc) which is what AngularJS uses to detect instances of FormData. You can see that here, https://github.com/angular/angular.js/blob/9f7144b035800c6671a981ba7e5987aeb6c9e959/src/Angular.js#L689
Object.toString looks at the special toStringTag symbol to figure out what to return. I have tested the fix I mentioned above and it fixes the issues we were seeing using multi-part file upload in AngularJS (using Cordova with WKWebView and this plugin).
Here’s the fix we are using. I would be happy to submit a pull request.
@elliottpalermo Thanks Elliot. We are currently in process of pushing changes to the repo. We will publish the changes soon that will take care of modifying the implementation of "toString" to resolve the issue identified by you.
@elliottpalermo Issue has been fixed and Latest plugin version (2.1.3) is released to npm.
The FormData polyfil does not set the toStringTag symbol which will cause Object.toString to incorrectly report these objects as "[object Object]" instead of "[object FormData"]
This causes issues when attempting to use multi-part file upload in AngularJS. If you do not specify the content type and post a form using $http, AngularJS is supposed to automatically detect the FormData and set the content type and boundry automatically.
It seems that this can be fixed by setting the Symbol correctly, something like: