apache / apache/cordova-android

mapUriToFile has no implementation for `http` / `https` schemes

Open
#1,496 2 comments 0 reactions 0 assignees View on GitHub
bug discussion Requires Triage
Dominant language
JavaScript
Stars
3.8k
Forks
1.6k
Avg merge
16h 18m
Merged PRs (30d)
11

Description

https://github.com/apache/cordova-android/blob/954d3e0e7542356e6ea995ddc75dcb1db8bb36cc/framework/src/org/apache/cordova/CordovaResourceApi.java#L149-L173

The `cordova-plugin-file-transfer` plugin utilizes this method to map a uri value such as `http://localhost/__cdvfile_persistent__/testFile.txt` to a local file url, when using the file transfer's download API. However because this API does not handle the `http` scheme, it returns a Null, which eventually leads to a `NullPointerException` and failing unit tests.

the `testFile.txt` url comes from the [following code](https://github.com/apache/cordova-plugin-file-transfer/blob/2465f508adfadd5be4a8ea9ecd1ca01779164ea2/tests/tests.js#L333-L335):

```javascript
this.root = this.persistentRoot;
this.fileName = 'testFile.txt';
this.localFilePath = this.root.toURL() + this.fileName;
```
Where `this.persistentRoot` [resolved by](https://github.com/apache/cordova-plugin-file-transfer/blob/2465f508adfadd5be4a8ea9ecd1ca01779164ea2/tests/tests.js#L215-L225):

```javascript
window.requestFileSystem(
LocalFileSystem.PERSISTENT,
DEFAULT_FILESYSTEM_SIZE,
function (fileSystem) {
specContext.persistentRoot = fileSystem.root;
done();
},
function () {
throw new Error('Failed to initialize persistent file system.');
}
);
```

I'm raising the issue here because the method in question is located inside cordova-android, but it's unclear if the solution is to update `mapUriToFile` support this use case, or if the file transfer plugin should expect `file://` urls instead of http:// urls.

Contributor guide

Open the contributing guide

Research direction

Start with framework/src/org/apache/cordova/CordovaResourceApi.java at lines 149-173 and trace the mapUriToFile URI contract. Reproduce the file-transfer path described in tests/tests.js at lines 215-225 and 333-335, then determine whether Android or the plugin should own http/https handling; done means the null result, NPE, and failing tests are resolved under the agreed contract.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java, javascript
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.