cordovacordova-pluginscordova-plugin-file

How to use w3c File object in cordova with cordova-plugin-file installed?


I'm trying to create a File object with the default File() constructor but since cordova-plugin-file replaces the constructor with it's own implementation of the File() constructor, I'm not able to get the File object. Is there any way to access the w3c File constructor without removing the file plugin?

Also, Will it be possible to edit the plugin such that the File() constructor could be renamed to anything else like FileCordova() so that both default and the plugin's constructor could be accessed?

PS : I need the File object to pass in a function that only accepts the w3c File object, so the object returned by the plugin is pretty much useless for me.


Solution

  • I figured it out by editing the cordova-plugin-file. I edited the plugin.xml at /Project/plugins/cordova-plugin-file/

    I changed this :

     <js-module src="www/File.js" name="File">
        <clobbers target="window.File" />
    </js-module>
    

    to this :

    <js-module src="www/File.js" name="File">
        <clobbers target="window.FileC" />
    </js-module>
    

    After editing the file, I went to the cordova cmd and removed all platforms I had

    cordova platform remove android
    cordova platform remove browser
    

    I then added them back again, since this is the only way to reload a plugin into the assets folder into the platform.

    cordova platform add android
    cordova platform add browser
    

    After this I'm able to get the default File object with the new File() constructor and the file plugin's File object with new FileC() constructor.