Skip to content

Commit 5e5ac4e

Browse files
committed
Fix for iOS with cordova-plugin-file >=8.1.3
1 parent f12b73e commit 5e5ac4e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

www/FileTransfer.js

+15
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ const FileTransfer = function () {
7575
this.onprogress = null; // optional callback
7676
};
7777

78+
const iOSPathFix = function (path) {
79+
if (window.CDV_ASSETS_URL) {
80+
const pathstart = window.CDV_ASSETS_URL + '/_app_file_';
81+
if (path.startsWith(pathstart)) {
82+
return 'file://' + path.substring(pathstart.length);
83+
}
84+
}
85+
return path;
86+
};
87+
7888
/**
7989
* Given an absolute file path, uploads a file on the device to a remote server
8090
* using a multipart HTTP request.
@@ -87,6 +97,9 @@ const FileTransfer = function () {
8797
*/
8898
FileTransfer.prototype.upload = function (filePath, server, successCallback, errorCallback, options, trustAllHosts) {
8999
argscheck.checkArgs('ssFFO*', 'FileTransfer.upload', arguments);
100+
101+
filePath = iOSPathFix(filePath);
102+
90103
// check for options
91104
let fileKey = null;
92105
let fileName = null;
@@ -172,6 +185,8 @@ FileTransfer.prototype.download = function (source, target, successCallback, err
172185
argscheck.checkArgs('ssFF*', 'FileTransfer.download', arguments);
173186
const self = this;
174187

188+
target = iOSPathFix(target);
189+
175190
const basicAuthHeader = getBasicAuthHeader(source);
176191
if (basicAuthHeader) {
177192
source = source.replace(getUrlCredentials(source) + '@', '');

0 commit comments

Comments
 (0)