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: Filesystem doesn't create directory or write files. overall write fails for everything. even with the permissions allowed #2827

Closed
2 of 4 tasks
qanuj opened this issue Apr 25, 2020 · 7 comments

Comments

@qanuj
Copy link

qanuj commented Apr 25, 2020

Bug Report

Capacitor Version

npx cap doctor output:
Latest Dependencies:
@capacitor/cli: 2.0.1
@capacitor/core: 2.0.1
@capacitor/android: 2.0.1
@capacitor/electron: 2.0.1
@capacitor/ios: 2.0.1

Installed Dependencies:
@capacitor/electron not installed
@capacitor/ios 2.0.0
@capacitor/core 2.0.0
@capacitor/cli 2.0.0-beta.1
@capacitor/android 2.0.0

Affected Platform(s)

  • Android
  • iOS
  • Electron
  • Web

Current Behavior

Filesystem.mkdir({ directory: FilesystemDirectory.Data, path: "pictures"}).catch(err => {
console.log('folder create warning', err.message);
});
doesn't create any folder, doesn't write any files. even after asking for permissions and permission defined from app info, yet fails to do so. I though I was paranoid, so I picked up old project which was working fine, and downloading on device, I uninstalled the app, rebuild it and then it stopped working. no npm install. plain ionic build --prod to run it on device. and this code based was not changed in last week or so.

Expected Behavior

It should be able to write files or create directories.

Sample Code or Sample Application Repo

Reproduction Steps

Other Technical Details

npm --version output:
6.11.3
node --version output:
v12.16.1
pod --version output (iOS issues only):

Other Information

@qanuj qanuj changed the title bug: bug: Filesystem doesn't create directory or write files. overall write fails for everything. even with the permissions allowed Apr 25, 2020
@snow-drop
Copy link

Hi. I'm currently playing with the Filesystem plugin and seems to work fine. I'm testing it on Android 6.0 Marshmallow with the latest capacitor dependencies all in 2.0.1. It might help them if you put your device's OS also on Other Technical Details.

@qanuj
Copy link
Author

qanuj commented Apr 26, 2020

I have tested with 3 different devices, 2 Android, 1 iOS. All fails writing file to storage. I created a fresh app with following commands.

ionic start
ionic build
npx cap add android
npx cap sync android

in home.page.html

...................

  <ion-list>
    <ion-item>
      <ion-label position="stacked">Folder Name</ion-label>
      <ion-input [(ngModel)]="rec.folder"></ion-input>
      <ion-icon color="primary" slot="end" 
            (click)="createFolder(rec.folder)" slot="end" name="add"></ion-icon>
    </ion-item>
  </ion-list>

......................

in home.page.ts

...................

rec: any = {};
 message: string;

 constructor() { }

 createFolder(folder: string) {
Filesystem.mkdir({ directory: FilesystemDirectory.Data, path: folder, recursive: true })
     .then(result => {
       this.message = 'created folder :' + folder;
     })
     .catch(err => {
       this.message = 'folder create warning :' + err.message;
     });
 }

...................

and it doesn't ask for permissions on fresh install, and it presents, black "{}" response for first create and then throws catch error saying folder existings. which is expected.

then I just close the app, and relaunch it.

create the same folder again and it shows success. and then create again fails.

  1. First Launch.
  2. Create Folder Demo [Works]
  3. Again Create Folder Demo [Failes]
  4. Close the App
  5. Second launch
  6. Create Folder Demo [Works] (which should have folder if the folder did create in step 2)
  7. Again Create Folder Demo [Failes]

Note
If I change the directory as following, it does as for permission but the logs below present that it fails for unknown reasons.

Filesystem.mkdir({ directory: FilesystemDirectory.Documents, 
                                path: folder, recursive: true })
.then(result => {
   this.message = 'created folder :' + folder;
}).catch(err => {
   this.message = 'folder create warning :' + err.message;
});
V/Capacitor/Plugin/Filesystem: Permission 'android.permission.WRITE_EXTERNAL_STORAGE' is granted
D/Capacitor: Sending plugin error: {"save":false,"callbackId":"85014852","pluginId":"Filesystem","methodName":"mkdir","success":false,"error":{"message":"Unable to create directory, unknown reason"}}

D:\code\DemoDemoDemo>npx cap doctor
Capacitor Doctor
Latest Dependencies:
@capacitor/cli: 2.0.1
@capacitor/core: 2.0.1
@capacitor/android: 2.0.1
@capacitor/electron: 2.0.1
@capacitor/ios: 2.0.1

Installed Dependencies:
@capacitor/ios not installed
@capacitor/electron not installed
@capacitor/cli 2.0.1
@capacitor/android 2.0.1
@capacitor/core 2.0.1

[success] Android looking great! 👌

@snow-drop
Copy link

snow-drop commented Apr 26, 2020

By your statement "create the same folder again and it shows success. and then create again fails.", you mean, you allow the app to create the folder and it successfully created one? and then when you do it again, it displays the error that the folder already exists?

Also, could you try running the following code in Android? I omitted the directory option and manually set the path there to make sure that the directory option can't conflict with the mkdir().

await Filesystem.mkdir({
    path: '/storage/self/primary/NewFolder',
    recursive: true
})

The /storage/self/primary/ points to the internal SD card.

I also encountered this error several hours ago:

{"message":"Unable to create directory, unknown reason"}

But mine was, instead of FilesystemDirectory.Documents, i wrote FilesystemDirectory.DOCUMENTS. That's why I omitted the directory option first to confirm if writing with a manually crafted path will work or not.

@qanuj
Copy link
Author

qanuj commented Apr 26, 2020

I am able to narrow down that fact that folders and files are created yet. even this, results in error in the catch method. though using the adb-shell command I can see the files and folders are all created fine in data director. (this is private folder).

Filesystem.stat({ directory: FilesystemDirectory.Data, path: '' }).then(result => {
      console.log(result.uri);
    }).catch(err => {
      console.log('Error', err.message);
    });

most strange thing is that when I look a the code in Filesystem.java it says File does not exist but the error here says Entrydoes not exist.

@jcesarmobile
Copy link
Member

can you provide a sample app?

@jcesarmobile jcesarmobile added the needs reply needs reply from the user label Apr 27, 2020
@jcesarmobile
Copy link
Member

closing as there was no answer

@jcesarmobile jcesarmobile removed the needs reply needs reply from the user label May 22, 2020
@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.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants