I'm having a hard time with a basic filesystem issue when both running in the browser with ionic serve as well as ionic run browser
I've run the browser with the correct flags to allow for local system access but I'm still getting some sort of security error:
It was determined that certain files are unsafe for access within a Web application, or that too many calls are being made on file resources.
My code:
this.file.checkDir(this.file.dataDirectory, 'media').then(() => {
// Media Directory Exists, do nothing.
console.log('Media Storage Loaded');
}).catch(err => {
console.log('Media Storage not found... Creating');
this.file.createDir(this.file.dataDirectory, 'media', false).then(dir => {
console.log('Media Directory Created!');
}).catch(err => {
console.log('CRITICAL ERROR. MEDIA STORAGE DIRECTORY FAILED TO BE CREATED:', err);
console.log('Because of this, media files cannot be stored or loaded locally');
});
});
I ran console.log(this.file) and got an object that lists the dataDirectory as: filesystem:file:///persistent/
I can't create a file or a directory and I'm not really sure why.
There are a bunch of examples for the cordova specific plugin but very little with ionic-native and the file system.
I'm using Ionic 2.2.2 and ionic-native 3.4.4 on Mac/Chrome @latest
Same problem seen here. It seems Chrome and Chromium no longer allow creating files or directories.
Here is one Stack Overflow report of this problem (but seen with cordova-plugin-file).
Here is my code that causes the same error message, which is
SecurityError: It was determined that certain files are unsafe for access within a Web application, or that too many calls are being made on file resources.
This error gets reported in the catch() block of this code:
window.addEventListener('filePluginIsReady', function() {
file.createDir(file.dataDirectory, 'woohoo', true).then(
_ => console.log('We did it!!!')
).catch(err => console.log(err));
}, false);
which I put at the beginning of app.component.ts.
Versions, from package.json:
"@ionic-native/core": "3.13.1",
"@ionic-native/file": "^4.1.0",
"ionic-angular": "3.6.0",
Note 1: The browser did ask, with the typical alert, whether the app can get access to files stored locally on the device and of course I answered 'Yes' to give the app permissions. This security error seems to always show up.
Note 2: This all happened after starting chrome with the '--allow-file-access-from-files' flag from the command line
Note 3: The same problem shows up in Chromium
Thanks, glad it's not just me.
I was able to use vanilla JS to save to the localFS for testing purposes so I'm pretty sure the issue is in however cordova/ionic is doing it..
Could you please elaborate with code? If not, could you please mention what worked for you? Did you use the HTML5 File API? Did you ever create a file or a directory successfully via JS in the browser? Did it work in the mobile version of the browser as well? Thanks!
So, if you look at cordova-file-plugin you can see it says it is based on the Filesystem API spec that only chrome supports. So I just use the basic stuff here
On using the file system. When I request on my own I'm able to resolve a file system, and when I tear into the file-plugin I can see it using similar code. If I do a plain cordova example (non ionic) that uses the file-plugin I'm able to get it to work.. No specific examples at the moment, I might make a pen if it becomes more of a pain
Currently, I present the similar error, to test my applications i used Chrome
I use Version 69.0.3497.100 (Official Build) (64 bits), which is supposed to be the last one available.
But I have searched the web and the -allown-origin (CORS), for access to the files, it does not work, I see that they say that for testing modes it uses the localFS script, but unfortunately I have not found an example of it.
I know that My question may be silly.
I hope response thanks for your help.
Most helpful comment
So, if you look at cordova-file-plugin you can see it says it is based on the Filesystem API spec that only chrome supports. So I just use the basic stuff here
On using the file system. When I request on my own I'm able to resolve a file system, and when I tear into the file-plugin I can see it using similar code. If I do a plain cordova example (non ionic) that uses the file-plugin I'm able to get it to work.. No specific examples at the moment, I might make a pen if it becomes more of a pain