Capacitor: bug: Error: "Parent folder doesn't exist" when using FileSystem

Created on 31 Mar 2020  ·  9Comments  ·  Source: ionic-team/capacitor

Bug Report

Capacitor Version

npx cap doctor output:

💊 Capacitor Doctor 💊

Latest Dependencies:

@capacitor/cli: 1.5.2

@capacitor/core: 1.5.2

@capacitor/android: 1.5.2

@capacitor/ios: 1.5.2

Installed Dependencies:

@capacitor/cli 1.4.0

@capacitor/core 1.4.0

@capacitor/android 1.4.0

@capacitor/ios 2.0.0-beta.1

Affected Platform(s)

  • [ ] Android
  • [x] iOS
  • [ ] Electron
  • [ ] Web

Current Behavior

When using FileSystem writeFile() gets an error "Parent folder doesn't exist"
My code was working perfectly till I update xcode

I am testing on IOS this happens in the phone as in the simulator from xcode

Expected Behavior

The file should be written with the path of the image

Sample Code or Sample Application Repo

async convertImage(imageUri) {
const { Camera, Filesystem } = Plugins;

const photoInTempStorage = await Filesystem.readFile({ path: imageUri });

const date = new Date(),
  time = date.getTime(),
  fileName = time + '.jpeg';

await Filesystem.writeFile({
  data: photoInTempStorage.data,
  path: fileName,
  directory: FilesystemDirectory.Data
});

const finalPhotoUri = await Filesystem.getUri({
  directory: FilesystemDirectory.Data,
  path: fileName
});

const photoPath = Capacitor.convertFileSrc(finalPhotoUri.uri);
// this.photo = this.domSanitizer.bypassSecurityTrustResourceUrl(photoPath);
this.images.push(photoPath);

}

deleteImage(imgEntry, position) {
this.images.splice(position, 1);
}

Reproduction Steps

I am testing on IOS this happens in the phone as in the simulator from xcode

With the capacitor camera I get the original photo path and the I send it to the convertImage(). Works fine until the writeFile() returns the "Parent folder doesn't exist" error

Other Technical Details

npm --version output: 6.9.0

node --version output: 10.16.0

pod --version output (iOS issues only): 1.9.1

Other Information

I am testing on IOS this happens in the phone as in the simulator from xcode

Most helpful comment

Thanks for the sample project, but the issue is already fixed, will be available on next release

All 9 comments

Can you provide a sample app?

I created an app with official demo "my-first-app"(example application that builds a camera with gallery)
and this error happens
image
image

Can confirm this, writing a file doesn't work for me either under iOS 13.4. Same error message.

People, when I ask for a sample app is not because I don't believe, it's to reproduce and fix it faster, so comments confirming don't help.

Can you provide a sample app?

https://github.com/quique24/file-demo

Here it is the demo app. It works fine with the created project but to reproduce the error is specifically in @capacitor/ios 2.0.0-beta.1

I run:
npm install @capacitor/ios@next
ionic cap update
And then its stops working returning de error

Thanks for the sample project, but the issue is already fixed, will be available on next release

Thanks for the sample project, but the issue is already fixed, will be available on next release

Thanks for the sample project, but the issue is already fixed, will be available on next release

i am having these versions
@capacitor/cli 2.4.0
@capacitor/android 2.4.0
@capacitor/core 2.4.0
still getting same error on android

And it looks to me that writing in subfolders is now broken.

I solve this issue by add this parameter: recursive: true

Filesystem will auto add any missing parent folders for us.

await this.Filesystem.writeFile({
                        path: 'my-folder/image.png',
                        data: base64data.toString(),
                        directory: FilesystemDirectory.Documents,
                        recursive: true
                    });
Was this page helpful?
0 / 5 - 0 ratings

Related issues

peterpeterparker picture peterpeterparker  ·  3Comments

danielsogl picture danielsogl  ·  3Comments

gnesher picture gnesher  ·  3Comments

natevw picture natevw  ·  3Comments

Hansel03 picture Hansel03  ·  3Comments