apache / apache/cordova-plugin-file-transfer
iOS: Download encounters "Invalid Server URL" if source file path contains non-English characters
- Dominant language
- JavaScript
- Stars
- 606
- Forks
- 874
- PR merge metrics
- No merged PRs in 30d
Description
# Bug Report
## Problem
File Transfer reports error when attempting to download a remote file with non-EN characters in the path/name. The file can be opened in browser with no issue.
### What is expected to happen?
Should download correctly regardless of the name.
### What does actually happen?
File Transfer Error: Invalid server URL https://xxxxxxxxx/SOME CHINESE CHARACTERS.pdf
## Information
I am using this in combination with Ionic 3.
### Command or Code
`downloadRemoteFile(downloadUrl, path, fileName){
const transfer = this.ft.create();
transfer.download(downloadUrl, path + fileName, true).then(entry => {
let url = entry.toURL();
this.openFileByPlatform(url);
},(err) => {
alert('download error');
});
}`
### Environment, Platform, Device
Only happens on iOS devices (tested on iOS 12+). Android is fine.
### Version information
"ionic-angular": "3.9.2",
"cordova-ios": "4.5.5",
"cordova-plugin-file-transfer": "1.7.1",
"@ionic-native/file-transfer": "^5.0.0",
### Workaround
Currently I need to modify the following line in CDVFileTransfer.m to fix the issue.
LINE 452:
Original:
`NSURL* sourceURL = [NSURL URLWithString:source];`
Modified:
`NSURL* sourceURL = [NSURL URLWithString:[source stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];`
## Checklist
- [x] I searched for existing GitHub issues
- [ ] I updated all Cordova tooling to most recent version
- [x] I included all the necessary information above
Contributor guide
Research direction
Start at CDVFileTransfer.m around line 452 and reproduce an iOS download whose remote path contains non-English characters, using the issue's Ionic example and the reported iOS versions. Compare the behavior with Android and verify that the file downloads successfully without producing an Invalid Server URL error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, javascript, objective-c
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100