apache / apache/cordova-plugin-file
Access to shared item in iOS not working
- Dominant language
- JavaScript
- Stars
- 744
- Forks
- 754
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 1
Description
I´m building a Cordova app for iOS (Vue / Quasar based [1]). I use the cordova-plugin-openwith-ios [2] Cordova plugin to share items (images, pdfs) from other apps to my app via the iOS Share Sheet. When the items are shared successfully a native file URI like `file:///var/mobile/Media/PhotoData/OutgoingTemp/3DD09AF1-75C5-4D6E-AC04-A539DEA401E5/1b91976f-8b9e-4eba-8699-505458907b4b.JPG` becomes available in my app. The cordova-plugin-openwith-ios docs hint that I need to use the cordova-plugin-file to actually access and use the shared file.
I tried out two different ways to access the file with cordova-plugin-file (taken directly from the documentation [4][5]). Directly on a device.
Given `item.data = file:///var/mobile/Media/PhotoData/OutgoingTemp/3DD09AF1-75C5-4D6E-AC04-A539DEA401E5/1b91976f-8b9e-4eba-8699-505458907b4b.JPG`
First approach
```javascript
window.resolveLocalFileSystemURL(
item.data,
function (entry) {
console.log('resolving')
var nativePath = entry.toURL()
console.log('Native URI: ' + nativePath)
},
function (err) {
console.error('resolveLocalFileSystemURL', err.code)
}
)
```
... results in `ERROR: resolveLocalFileSystemURL 1` (`NOT_FOUND_ERR`)
And second approach
```javascript
window.requestFileSystem(
window.LocalFileSystem.TEMPORARY,
0,
function (fs) {
console.log('file system open: ' + fs.name)
fs.root.getFile(
item.data,
{ create: false, exclusive: false },
function (fileEntry) {
console.log('fileEntry is file?' + fileEntry.isFile.toString())
},
function (err) {
console.error('getFile', err.code)
}
)
},
function (err) {
console.error('requestFileSystem', err.code)
}
)
```
... results in `ERROR: getFile 5` (`ENCODING_ERR`)
I already looked extensively for possible hints to what might cause this (SO, Cordova Forums, Plugin Forums, here, Quasar Forums), but had no luck so far. Exploration of the cordova-plugin-file source code (tracing the error codes, etc) also gave me no clue to what might be the issue.
Anyone any ideas where to look next?
```bash
❯ cordova -v
9.0.0 (cordova-lib@9.0.1)
❯ cordova requirements
Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed android-29,android-28,android-23
Gradle: installed /usr/local/Cellar/gradle/6.1.1/bin/gradle
Requirements check results for ios:
Apple macOS: installed darwin
Xcode: installed 11.5
ios-deploy: installed 1.10.0
CocoaPods: installed 1.8.4
❯ cordova plugin
cordova-plugin-file 6.0.2 "File"
cordova-plugin-openwith-ios 1.0.0 "OpenWith"
cordova-plugin-whitelist 1.3.4 "Whitelist"
```
`iOS: 13.5.1`
[1] https://quasar.dev
[2] https://github.com/EternallLight/cordova-plugin-openwith-ios
[3] https://github.com/apache/cordova-plugin-file
[4] https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#cdvfile-protocol
[5] https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#sample-create-files-and-directories-write-read-and-append-files-
Contributor guide
Research direction
Start with the cordova-plugin-file documentation sections for the cdvfile protocol and sample file operations, then trace the resolveLocalFileSystemURL and requestFileSystem entry points in the plugin source. Compare their handling of the native URI from cordova-plugin-openwith-ios with the reported error codes; done means identifying the supported way to access these shared iOS files or documenting why the URI cannot be used.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, javascript
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100