I am using the file-transfer plugin and I am trying to download a file from an API, which has an authentification using cookies.
The problem I have is if I try to download a file, the cookie is not in the header : I have a 401 error. I have this problem only on ios, not on Android.
I have try to set the option 'withCredentials': true, with no luck.
So the problem is that the download is made from a native request, and the native layer doesn’t have the auth cookie, because the webview used by ios has trouble syncing cookies between the native layer and the webview.
We are now using cordova-plugin-fetch to make native http call in order to have cookies in the native layer, but that’s not ideal, because the cookie is different that the one from the webview.
Do you know any ways to sync cookies from the webview to the native layer without having to make http calls from the native layer? I have asked google with no luck yet…
Going back to UIWebView is not an option for me but I can’t find a solution.
Heliopsis, are you using cordova-plugin-fetch for all your requests or only the download one ? If only for download, how do you manage the different cookie values between the native layer and the webview ?
I was using UIWebView with Ionic1 ; all my requests to server (RubyOnRails using Devise) passed through the Devise authenticate_user! method without problem, and uploading files with $cordovaFileTransfer (also through authenticate_user!) was fine.
I switched to WkWebView on client side (using cordova-plugin-ionic-webview plugin).
All my requests to server are still fine (no problem with Devise authenticate_user! method) except uploads (still with $cordovaFileTransfer): Devise rejects any upload with a 401 error.
Some clue: although all my standard requests (logged on server side) include HTTP_COOKIE values (with a ‘_front_session’ value), permitting Devise to find my session back, all my upload requests are missing this HTTP_COOKIE param.
If this really is the cause of my problem, how can I get this _front_session cookie value on client side and add it to my header params when calling $cordovaFileTransfer.upload method ?
Do you have a sample of what you did after installing the plugin ?
Currently I’m facing the same issue. I’ve migrated my app from using UIWebView to WKWebView and now file-transfer is not working (returning 401). Did you found a solution for this?