@capacitor/filesystem downloadFile() fails to create missing directories under android
Bug Report
The downloadFile() method doesn't create missing directories under android.
Plugin(s)
@capacitor/[email protected]
Capacitor Version
💊 Capacitor Doctor 💊
Latest Dependencies:
@capacitor/cli: 5.4.2
@capacitor/core: 5.4.2
@capacitor/android: 5.4.2
@capacitor/ios: 5.4.2
Installed Dependencies:
@capacitor/core: 5.4.2
@capacitor/android: 5.4.2
@capacitor/cli: 5.4.2
@capacitor/ios: 5.4.2
[success] iOS looking great! 👌
[success] Android looking great! 👌
Platform(s)
Android
Current Behavior
Download fails on android, when setting the option recursive to true and providing a path with subdirectories that doesn't exist.
Filesystem.downloadFile({
url: 'https://images.unsplash.com/photo-1510158105534-9b01f2462ce1',
path: '/path/to/file/image.jpg',
directory: Directory.Cache,
recursive: true,
});
The above code will result in the following error.
ERROR Error: Uncaught (in promise): Error: Error downloading file: /data/user/0/io.ionic.starter/cache/path/to/file/image.jpg: open failed: ENOENT (No such file or directory)
Error: Error downloading file: /data/user/0/io.ionic.starter/cache/path/to/file/image.jpg: open failed: ENOENT (No such file or directory)
Expected Behavior
The missing folders should be created and the file should be saved at the specified path. On iOS, the missing folders are created.
Code Reproduction
Repository with minimal reproduction
Other Technical Details
Tested on native android device with android version 13.
Changing or omitting the directory option does not change the behavior, only the error message becomes slightly different. If you create the folder beforehand with the mkdir function, the download also works.
Additional Context
Error in Logcat
Error downloading file: /data/user/0/io.ionic.starter/cache/path/to/file/image.jpg: open failed: ENOENT (No such file or directory)
java.io.FileNotFoundException: /data/user/0/io.ionic.starter/cache/path/to/file/image.jpg: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:574)
at java.io.FileOutputStream.(FileOutputStream.java:236)
at com.capacitorjs.plugins.filesystem.Filesystem.downloadFile(Filesystem.java:339)
at com.capacitorjs.plugins.filesystem.FilesystemPlugin.downloadFile(FilesystemPlugin.java:401)
at java.lang.reflect.Method.invoke(Native Method)
at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138)
at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:780)
at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Unknown Source:0)
at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.os.HandlerThread.run(HandlerThread.java:67)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:563)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:274)
at libcore.io.ForwardingOs.open(ForwardingOs.java:563)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7804)
at libcore.io.IoBridge.open(IoBridge.java:560)
at java.io.FileOutputStream.(FileOutputStream.java:236)
at com.capacitorjs.plugins.filesystem.Filesystem.downloadFile(Filesystem.java:339)
at com.capacitorjs.plugins.filesystem.FilesystemPlugin.downloadFile(FilesystemPlugin.java:401)
at java.lang.reflect.Method.invoke(Native Method)
at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138)
at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:780)
at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Unknown Source:0)
at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.os.HandlerThread.run(HandlerThread.java:67)
This issue has been labeled as type: bug. This label is added to issues that that have been reproduced and are being tracked in our internal issue tracker.
Same issue here :,)
any fix on this issue?
Same issue here
Same here.
And same...
This issue is still persisting. Do we know the solution for this issue. Also, the getUri() fails and crashes the app.