The overall problem I’m trying to solve is to create a file on the phone’s filesystem and then write into it.
What I’m trying to achieve: In my app, the user takes full-size pictures, that I move from cache folder to files folder. Next step is to create thumbnails for these pictures. I already have a solution using HTML canvas that returns a base64-encoded jpg image. I also have found a method to convert this string into a blob. Now I want to save that blob to a file on the phone (that will be used as preview in a gallery as the full-sized images take way to long to load).
ionic-native file plugin
I’ve checked the File plugin from ionic-native. It has a createFile() method which works, but I see no write method or similar, which means I can create an empty file but not write into it (? … Or at least I don’t know how to).
I already use the File plugin from ionic-native to move files from cache folder to files folder in the app’s data folder which works nicely, however it’s not really cross-platform as there are no file sytem constants (like file.cacheDirectory and file.dataDirectory that are defined in the cordova file plugin), which means right now my code is android-specific, which is another drawback of the ionic-native file plugin.
cordova file plugin
The cordova file plugin seems to be advantageous as it has these constants and also a writeFile() method.
To test this plugin I’ve done the following (running on a Linux machine):
Everything runs through smoothly, the app builds and runs on my android phone, I can access the camera, I can access and move the image file on the phone, etc. No problem there.
I learned from a previous problem that I have to write declare var cordova: any; in the file where I want to access cordova plugins, so I did that.
But when I do console.log(cordova.plugins) it only shows the Keyboard plugin. console.log(cordova.plugins.file) yields undefined.
What I need
Simply put: a way to write into a file.
Best thing would be if someone could point me to what I’m missing in my attempt to use cordova file plugin.
@oh_lordy it looks like the file plugin exposes the file directly via cordova cordova.file instead of cordova.plugins.file. Can you console log cordova.file to check if it’s there? Please remember to do that after the platform has been ready: