Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Ask permission when using Filesystem.readFile or add permission into the Permission plugin #3492

Closed
mwyld opened this issue Sep 1, 2020 · 7 comments

Comments

@mwyld
Copy link

mwyld commented Sep 1, 2020

Bug Report

Capacitor Version

Latest Dependencies:

@capacitor/cli: 2.4.0
@capacitor/core: 2.4.0
@capacitor/android: 2.4.0
@capacitor/electron: 2.4.0
@capacitor/ios: 2.4.0

Installed Dependencies:

@capacitor/electron not installed
@capacitor/cli 2.2.0
@capacitor/core 2.2.0
@capacitor/android 2.2.0
@capacitor/ios 2.2.0

[success] Android looking great! 👌
Found 4 Capacitor plugins for ios:
@capacitor-community/fcm (1.0.8)
@capacitor-community/firebase-analytics (0.2.0)
@capacitor-community/media (1.0.1)
cordova-plugin-camera (4.1.0)
[success] iOS looking great! 👌

Platform(s)

iOS

Current Behavior

When reading a file using the Filesystem plugin I am getting a permission issue. I can't find a solution

Expected Behavior

Prompt for permission when using the Filesystem plugin or add an extra functionality to do this in capacitor Permission plugin

Code Reproduction

When calling await Filesystem.readFile({ path }) I am receiving:

[error] - Error: Uncaught (in promise): Error: The file “123.MOV” couldn’t be opened because you don’t have permission to view it.

Other Technical Details

none

Additional Context

Is there a quick workaround for this issue I could implement now?

@jcesarmobile
Copy link
Member

iOS don't require permissions to read files, but can only read files inside its own sandbox, so you are probably trying to open a file outside the sandbox. Hard to tell because you didn't provide a sample app.

@mwyld
Copy link
Author

mwyld commented Sep 1, 2020

Apologies. Here is a bit more detail:

I am trying to grab a video but it doesn't seem possible in capacitor so I am using the cordova Camera plugin and the mediaType of VIDEO. I'm then using the returned FILE_URI to get the video so later I can upload it to vimeo

this.camera.getPicture({
        destinationType: this.camera.DestinationType.FILE_URI,
        sourceType: this.camera.PictureSourceType.SAVEDPHOTOALBUM,
        mediaType: this.camera.MediaType.VIDEO
      }).then(async (path) => {


        let video;
        try {
          video = await Filesystem.readFile({
            path
          })
        } catch (err) {
           console.log(err)
        }
});

@spasma
Copy link

spasma commented Sep 7, 2020

I'm having this very same issue today.

While using the @ionic/camera (cordova-plugin-camera) within a capacitor app and reading a video from the library, it states: The file “filename.ext” couldn’t be opened because you don’t have permission to view it..

Reading image files from library with the exact same plugin is actually working perfectly, I suspect due the the following difference;

The file is compressed (trimmed as iOS calls it) by cordova-plugin-camera and it looks like the directory is outside app scope:

This is an example of a trimmed file which is somehow unreachable by the app:
file:///private/var/mobile/Containers/Data/PluginKitPlugin/29878464-6445-4365-8689-FCE4915154EA/tmp/trim.379A14E0-5AB7-4536-89BA-FA82008DF56E.MOV

@mwyld
Copy link
Author

mwyld commented Sep 7, 2020

I still haven't found a solution to this, but will post here if I do. Would you let me know if you do too? Ideally this ticket could do with being re-opened

@calls9-mattwyld
Copy link

Hey @spasma and @agomezmoron

I've had another crack at this, if you copy the video into cache then read from that it seems to work okay.
Here's my code snippet

let video;
await Filesystem.copy({
            from: path,
            to: 'my-apps-video.MOV',
            toDirectory: FilesystemDirectory.Cache
    }).then(async () => {
         video = await Filesystem.readFile({
              directory: FilesystemDirectory.Cache,
              path: 'my-apps-video.MOV'
         })
})

@spasma
Copy link

spasma commented Sep 10, 2020

Hi @mwyld, thank you for sharing your findings. A few days ago I found this issue on the camera plug-in, but I haven't checked the solution yet. My client postponed the options to select videos from the library due to the issue.

apache/cordova-plugin-camera#506 (comment)

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 11, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants