Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-12531

File not found when selecting from Google Drive folder

Details

    • Bug
    • Status: Reopened
    • Major
    • Resolution: Unresolved
    • 4.3.2
    • None
    • cordova-plugin-file
    • None
    • android

    Description

      In Android, when using an <input type="file"> and selecting a file from the Drive folder, and then trying to upload it with JS, produces a file not found error.

      Here is a project using the Firebase SDK that reproduces the error and more detailed description of the problem:
      https://github.com/PierBover/firebase-upload-cordova

      At first I thought the problem was in the Firebase SDK, but I replaced it with Filestack and the problem persists. Also the Firebase support team reproduced the error and in their opinion it is a problem with the Cordova app.

      When trying to upload a file to a website like imgur.com using Chrome it works fine so it could be related to some obscure permissions.

      Hopefully someone here will be able to rule out if it's an Android bug or some limitation of Cordova.

      Attachments

        Activity

          kerrishotts Kerri Shotts added a comment -

          Can you share the output of the following?

          cordova platforms ls
          cordova plugins ls

          Also, does the issue occur on all Android devices you've tried? Can you get device logs from the same time and post those (adb logcat)?

          kerrishotts Kerri Shotts added a comment - Can you share the output of the following? cordova platforms ls cordova plugins ls Also, does the issue occur on all Android devices you've tried? Can you get device logs from the same time and post those (adb logcat)?
          pierbover Pier Bover added a comment -

          These are on the demo project I posted earlier.

          Installed platforms:
          android 6.1.2
          browser 4.1.0

          And:

          cordova-plugin-whitelist 1.3.1 "Whitelist"

          I've tried it on a Nvidia Shield tablet with Nougat, and with a Moto X Style with Marshmallow. Same result.

          pierbover Pier Bover added a comment - These are on the demo project I posted earlier. Installed platforms: android 6.1.2 browser 4.1.0 And: cordova-plugin-whitelist 1.3.1 "Whitelist" I've tried it on a Nvidia Shield tablet with Nougat, and with a Moto X Style with Marshmallow. Same result.
          pierbover Pier Bover added a comment -

          Here is the result from adb logcat.

          https://gist.github.com/PierBover/f11a5da174463ca3b6d44d54e93ee225

          It starts form the moment the app opens, to the moment it's killed. Hopefully someone will be able to find something useful in there.

          pierbover Pier Bover added a comment - Here is the result from adb logcat. https://gist.github.com/PierBover/f11a5da174463ca3b6d44d54e93ee225 It starts form the moment the app opens, to the moment it's killed. Hopefully someone will be able to find something useful in there.
          pierbover Pier Bover added a comment -

          This seems to be the related Exception:

          3-02 13:17:49.793 29546 29592 W Documents: Failed to query
          03-02 13:17:49.793 29546 29592 W Documents: android.os.OperationCanceledException: The operation has been canceled.
          03-02 13:17:49.793 29546 29592 W Documents: at android.os.CancellationSignal.throwIfCanceled(CancellationSignal.java:54)
          03-02 13:17:49.793 29546 29592 W Documents: at android.content.ContentProviderClient.query(ContentProviderClient.java:132)
          03-02 13:17:49.793 29546 29592 W Documents: at com.android.documentsui.DirectoryLoader.loadInBackground(DirectoryLoader.java:167)
          03-02 13:17:49.793 29546 29592 W Documents: at com.android.documentsui.DirectoryLoader.loadInBackground(DirectoryLoader.java:94)
          03-02 13:17:49.793 29546 29592 W Documents: at android.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:312)
          03-02 13:17:49.793 29546 29592 W Documents: at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:69)
          03-02 13:17:49.793 29546 29592 W Documents: at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:66)
          03-02 13:17:49.793 29546 29592 W Documents: at android.os.AsyncTask$2.call(AsyncTask.java:295)
          03-02 13:17:49.793 29546 29592 W Documents: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
          03-02 13:17:49.793 29546 29592 W Documents: at com.android.documentsui.ProviderExecutor.run(ProviderExecutor.java:107)

          pierbover Pier Bover added a comment - This seems to be the related Exception: 3-02 13:17:49.793 29546 29592 W Documents: Failed to query 03-02 13:17:49.793 29546 29592 W Documents: android.os.OperationCanceledException: The operation has been canceled. 03-02 13:17:49.793 29546 29592 W Documents: at android.os.CancellationSignal.throwIfCanceled(CancellationSignal.java:54) 03-02 13:17:49.793 29546 29592 W Documents: at android.content.ContentProviderClient.query(ContentProviderClient.java:132) 03-02 13:17:49.793 29546 29592 W Documents: at com.android.documentsui.DirectoryLoader.loadInBackground(DirectoryLoader.java:167) 03-02 13:17:49.793 29546 29592 W Documents: at com.android.documentsui.DirectoryLoader.loadInBackground(DirectoryLoader.java:94) 03-02 13:17:49.793 29546 29592 W Documents: at android.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:312) 03-02 13:17:49.793 29546 29592 W Documents: at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:69) 03-02 13:17:49.793 29546 29592 W Documents: at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:66) 03-02 13:17:49.793 29546 29592 W Documents: at android.os.AsyncTask$2.call(AsyncTask.java:295) 03-02 13:17:49.793 29546 29592 W Documents: at java.util.concurrent.FutureTask.run(FutureTask.java:237) 03-02 13:17:49.793 29546 29592 W Documents: at com.android.documentsui.ProviderExecutor.run(ProviderExecutor.java:107)
          kerrishotts Kerri Shotts added a comment -

          Does the app behave differently if you add the Cordova File plugin? cordova plugin add cordova-plugin-file

          Also – you've got API keys in that repo – probably don't want those to be public.

          I see some interesting things in the logcat, but there's a spot that refers to line 85 in your main.js file. I don't see a line 85 there in the repo, so I'm assuming the source has changed a little. Can you push your changes?

          kerrishotts Kerri Shotts added a comment - Does the app behave differently if you add the Cordova File plugin? cordova plugin add cordova-plugin-file Also – you've got API keys in that repo – probably don't want those to be public. I see some interesting things in the logcat, but there's a spot that refers to line 85 in your main.js file. I don't see a line 85 there in the repo, so I'm assuming the source has changed a little. Can you push your changes?
          pierbover Pier Bover added a comment -

          I'm having the same problem on another app which also has the File Plugin. Here is the list of plugins on that other app.

          code-push 1.9.0-beta "CodePushAcquisition"
          cordova-plugin-code-push 1.8.2-beta "CodePush"
          cordova-plugin-compat 1.0.0 "Compat"
          cordova-plugin-device 1.1.2 "Device"
          cordova-plugin-dialogs 1.3.0 "Notification"
          cordova-plugin-file 4.2.0 "File"
          cordova-plugin-file-transfer 1.5.1 "File Transfer"
          cordova-plugin-nativestorage 2.0.2 "NativeStorage"
          cordova-plugin-network-information 1.3.0 "Network Information"
          cordova-plugin-statusbar 2.2.0 "StatusBar"
          cordova-plugin-whitelist 1.3.0 "Whitelist"
          cordova-plugin-zip 3.1.0 "cordova-plugin-zip"

          Also – you've got API keys in that repo – probably don't want those to be public.

          Eh, it doesn't matter. It's a free firebase project.

          pierbover Pier Bover added a comment - I'm having the same problem on another app which also has the File Plugin. Here is the list of plugins on that other app. code-push 1.9.0-beta "CodePushAcquisition" cordova-plugin-code-push 1.8.2-beta "CodePush" cordova-plugin-compat 1.0.0 "Compat" cordova-plugin-device 1.1.2 "Device" cordova-plugin-dialogs 1.3.0 "Notification" cordova-plugin-file 4.2.0 "File" cordova-plugin-file-transfer 1.5.1 "File Transfer" cordova-plugin-nativestorage 2.0.2 "NativeStorage" cordova-plugin-network-information 1.3.0 "Network Information" cordova-plugin-statusbar 2.2.0 "StatusBar" cordova-plugin-whitelist 1.3.0 "Whitelist" cordova-plugin-zip 3.1.0 "cordova-plugin-zip" Also – you've got API keys in that repo – probably don't want those to be public. Eh, it doesn't matter. It's a free firebase project.
          pierbover Pier Bover added a comment -

          I see some interesting things in the logcat, but there's a spot that refers to line 85 in your main.js file. I don't see a line 85 there in the repo, so I'm assuming the source has changed a little. Can you push your changes?

          Yes sorry, I changed my local code. I've pushed the changes.

          When using the Filestack API the error thrown is different than the one desribed in github (when remote debugging from Chrome) but it's also a file not found.

          pierbover Pier Bover added a comment - I see some interesting things in the logcat, but there's a spot that refers to line 85 in your main.js file. I don't see a line 85 there in the repo, so I'm assuming the source has changed a little. Can you push your changes? Yes sorry, I changed my local code. I've pushed the changes. When using the Filestack API the error thrown is different than the one desribed in github (when remote debugging from Chrome) but it's also a file not found.
          jcesarmobile jcesarmobile added a comment -

          For allowing input file to work we have more like a workaround than a real solution.
          Google drive doesn't return an url for the file, but an input stream. We could create a temporary file from it and return the path to it.

          jcesarmobile jcesarmobile added a comment - For allowing input file to work we have more like a workaround than a real solution. Google drive doesn't return an url for the file, but an input stream. We could create a temporary file from it and return the path to it.
          pierbover Pier Bover added a comment -

          Thanks jcesarmobile

          Is there a way to detect when a file is coming from Drive instead of the downloads folder for example?

          pierbover Pier Bover added a comment - Thanks jcesarmobile Is there a way to detect when a file is coming from Drive instead of the downloads folder for example?
          jcesarmobile jcesarmobile added a comment -

          No, but here it won't be an url, the intent result should have the file content to create the temp file

          https://github.com/apache/cordova-android/blob/master/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java#L253-L273

          jcesarmobile jcesarmobile added a comment - No, but here it won't be an url, the intent result should have the file content to create the temp file https://github.com/apache/cordova-android/blob/master/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java#L253-L273
          pierbover Pier Bover added a comment -

          I solved it.

          Instead of passing the File object to upload I used a FileReader and converted File to arrayBuffer. I've pushed the solution to the github repo in case someone stumbles upon this.

          https://github.com/PierBover/firebase-upload-cordova

          pierbover Pier Bover added a comment - I solved it. Instead of passing the File object to upload I used a FileReader and converted File to arrayBuffer. I've pushed the solution to the github repo in case someone stumbles upon this. https://github.com/PierBover/firebase-upload-cordova
          pierbover Pier Bover added a comment -

          I'm narrowing this. I have encountered the error again.

          I solved the issue in my previous post by using FileReader. But since that project didn't use cordova-plugin-file it was using the browser's FileReader. And it works fine.

          In my current project I need cordova-plugin-file and cordova-plugin-file-transfer which means I'm not using the browser's FileTransfer but instead the implementation from cordova-plugin-file.

          I know this because for example I can't use reader.addEventListener(), which is implemented in the native version, but not on the one provided by cordova-plugin-file.

          From MDN:

          As FileReader inherits from EventTarget, all those events can also be listened for by using the addEventListener method.

          https://developer.mozilla.org/en/docs/Web/API/FileReader

          So, there is something broken in cordova-plugin-file.

          How can I use the browser's native FileTranfer in a project with cordova-plugin-file?

          pierbover Pier Bover added a comment - I'm narrowing this. I have encountered the error again. I solved the issue in my previous post by using FileReader. But since that project didn't use cordova-plugin-file it was using the browser's FileReader. And it works fine. In my current project I need cordova-plugin-file and cordova-plugin-file-transfer which means I'm not using the browser's FileTransfer but instead the implementation from cordova-plugin-file. I know this because for example I can't use reader.addEventListener(), which is implemented in the native version, but not on the one provided by cordova-plugin-file. From MDN: As FileReader inherits from EventTarget, all those events can also be listened for by using the addEventListener method. https://developer.mozilla.org/en/docs/Web/API/FileReader So, there is something broken in cordova-plugin-file. How can I use the browser's native FileTranfer in a project with cordova-plugin-file?

          People

            Unassigned Unassigned
            pierbover Pier Bover
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: