cordova-plugin-file icon indicating copy to clipboard operation
cordova-plugin-file copied to clipboard

Access to shared item in iOS not working

Open perelin opened this issue 4 years ago • 5 comments

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

        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

        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?

❯ cordova -v                                                                                              
9.0.0 ([email protected])

❯ 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-

perelin avatar Jun 28 '20 18:06 perelin

I got the same issue. Any solution?

Zapmobilegames avatar Nov 11 '20 21:11 Zapmobilegames

I got the same issue. Any solution?

huaigit avatar Mar 20 '21 01:03 huaigit

Same issue here. Any solution?

thomeijken avatar May 04 '21 15:05 thomeijken

+1 , Same problem...

gatelli avatar Jun 30 '21 20:06 gatelli

please refer to comments

SmallBlueE avatar Nov 29 '23 07:11 SmallBlueE