apache / cordova-plugin-file

Apache Cordova File Plugin
https://cordova.apache.org/
Apache License 2.0
741 stars 761 forks source link

open failed: ENOENT (No such file or directory) #550

Closed weversong2 closed 1 year ago

weversong2 commented 1 year ago

I've been using cordova-plugin-file for a while now and it's always worked perfectly.

But now with the update to SDK Minimum 31, it doesn't work as expected.

I use the following function to download:

window.cordova.plugin.ftp.download(externalDataDirectory.toURL() + 'einstein_sales.db', '/EINSTEIN_SALES/' + returnUSER.sf_company_name + '/' + returnUSER.sf_key + '/' + localStorage.getItem('bkpRESTORE ') + '', function (percent) { if (percent == 1) { $("#progres_bar_bkp_restore_ftp").html("<h4 style='color: blue;text-align: center'>Download/Restore Completed Successfully!</br>Wait for the app to restart...</h4> "); setTimeout(function() { window.location.href = "home.html"; }, 3000); ftpDISCONNECT(); } else { $("#progres_bar_bkp_restore_ftp").html(

${percent * 100}% Complete
                                                   </div>`);
             }, function(error) {
                 $("#progres_bar_bkp_restore_ftp").html("<h4 style='color: red;text-align: center'>Error Downloading BKP: " + error + "</h4>");
                 ftpDISCONNECT();`

I get following error: https://localhost:/__cdvfile_files-external__/einstein_sales.db: open failed: ENOENT (No such file or directory);

https://user-images.githubusercontent.com/18507991/208710200-0c81b774-61f3-4a37-898a-080cd0cff68b.jpeg https://user-images.githubusercontent.com/18507991/208710914-2a7bd7a6-46b2-4961-b04d-72a506b62eee.png https://user-images.githubusercontent.com/18507991/208710938-5ad264e3-e7a9-4567-ade9-982fce771335.jpeg

the application has the necessary permissions and the file is in the source folder.

breautek commented 1 year ago

You appear to be using some other plugin other then the apache file plugin here. Please show how the file plugin is being used.

Additionally toURL, which is handled by the webview. It's intended to be used in the DOM, but it looks like your handling this another plugin for native consumption. Assuming this is the File plugin DirectoryEntry object, it will have a .nativeURL property (not a method) instead that has a native file:// url that should be understandable by native code.

weversong2 commented 1 year ago

Strange, because I removed all plugins leaving only the cordova-plugin-file and the error persists.

I'm build sdk 31 android 11 cordova-plugin-file v7.0.1-dev

https://user-images.githubusercontent.com/18507991/208761858-e5d88cc4-f413-447b-a9ce-22348348c158.jpeg

breautek commented 1 year ago

I think there might be a miscommunication here.

window.cordova.plugin.ftp.download is not the file plugin.

externalDataDirectory.toURL() -- this does look part part of the file plugin API, but it simply just returns a URL that looks like https://localhost:/__cdvfile_files-external__/.... Nothing that is provided shows using cordova-plugin-file API to create or open a file. So I'm going on the assumption that your FTP plugin is what is attempting to consume the file path and attempting to open a file.

toURL() returns a file path usable by the DOM. Your FTP plugin probably won't understand this url, as the URL is only usable with Cordova's webview, which is configured to intercept https://localhost paths. Since you're interfacing with cordova plugin API instead of the DOM API, you probably want to use .nativeURL instead to obtain and pass a local file: path, instead of a https:// path.

If this doesn't work, then you need to provide us the code that actually opens the file.

weversong2 commented 1 year ago

Good morning mate. Plugin FT is just another resource that I use alongside Plugin File.

I'm sure it's not the FTP Plugin or any other, because the image I sent is a result of the following test I did:

window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function (externalDataDirectory) { alert(externalDataDirectory.toURL()) });

here I am putting purely the return of this directory.

The Plugin File I use with other resources such as accessing the SLite database, downloading files / recording files in the directory and etc.

as I explained above, I removed all plugins and left only the Plugin File to ensure that there is no interference, but I only get the same return from the directory..

weversong2 commented 1 year ago

The database path for example is: /storage/emulated/0/Android/data/com.eptusrondonia-einstein_sales/files/einstein_sales.db

To access this directory I use externalDataDirectory.toURL().

it has always worked that way and even the app is in production. however, with the sdk31 update, it stopped working.

weversong2 commented 1 year ago

SOLUTION!!!

I found out what was causing the problem. I updated cordova-plugin-media-capture to v4, but I must be having some error when using cordova-plugin-media-capture together with cordova-plugin-file.

So I rolled back the docordova-plugin-media-capture version to v3.0.3 and then everything worked normally.

Perhaps this incompatibility will be fixed soon.

Thanks for the help.