Skip to content

Conversation

@fabiofabbri84
Copy link

Platforms affected

iOS

Motivation and Context

Since cordova-plugin-file 8.1.3, on iOS, urls returned by Entry.toURL() are not anymore in 'file://' format, but in window.CDV_ASSETS_URL + '/_app_file_' format (where window.CDV_ASSETS_URL = scheme + '://' + hostname, and these values are defined in config.xml)

Description

I added a function that returns the 'file://' url if the url starts with window.CDV_ASSETS_URL + '/_app_file_'. Then I used it to filter the filePath and target values

I'm not sure if it is the best solution, but it works for me.

Testing

We have an app that had no issues with cordova-plugin-file <8.1.3 and cordova-plugin-file-transfer.

After an upgrade to cordova-plugin-file 8.1.3, we noticed file downloads with cordova-plugin-file-transfer was not working.

With this change to cordova-plugin-file-transfer, downloads are working again. As the additional function does nothing if the url does not start with window.CDV_ASSETS_URL + '/_app_file_', it should have no side effects

Checklist

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

@breautek
Copy link
Contributor

urls returned by Entry.toURL() are not anymore in 'file://' format,

.toURL() returns a DOM-usable URL, which could be file:// for non-scheme based webviews, or http(s):// on android, or app:// (or a chosen configured custom scheme name) on iOS.

Historically I think toURL() returned cdvfile:// urls, but got changed due to cross-origin limitations that appeared in WKWebView and modern android webview environments.

I believe file transfer plugin technically still accepts cdvfile:// urls, so perhaps there is old documentation recommending the use of entry.toURL() but if that is the case, I think the docs should be updated. cdvfile:// usage has been decommissioned for quite some time now.

.toURL() returns a transformed URL that can be parsed by the DOM and intercepted by the webview to find the relevant resource. iOS and android has different requirements here, so the URL returned will vary by platform. Entry objects have the original underlying property stored, I believe it's under .nativeURL (as a property, not a function).

So I feel like the better approach is to make sure documentation are up to date with current standards, and for application code to use the proper method/properties depending on their use case.

@fabiofabbri84
Copy link
Author

Well, the README.md says that this plugin works with the result of the .toURL() method, so I think the best path is to support all possible results of .toURL() and try to keep backward compatibility if you want to change this behaviour in future major versions (i think it's easy to recognize and support/convert a legacy url)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants