Saving resources to root or subfolder on device dynamically via webservice call

3 posts, 0 answers
  1. marko
    marko avatar
    20 posts
    Member since:
    Oct 2006

    Posted 29 Oct 2015 Link to this post

    Hi, I am trying to understand how I can dynamically save resources to the application storage area on a deployed application. We have a web service that makes a call, receives data and attempts to save the content as a file. I can actually save the file to the device without supplying any path and it seems to save it to the root folder on the internal storage i.e. "Device Storage" (obviously I am only ​referring to Android OS). I am using a Samsung S5 with Lollipop version of the OS. I used the sample file plugin using the write​Line method to do this.

    I want to be able to save ​my file to the same location as the index.html as shipped with my hybrid application i.e. the root folder of my application.

    If if interrogate the values of the following, running on the device I get:

    window.location.href => file:///data/data/<myAppName>/files/12590FAA-5EDD-4B12-856D-F52A0A1599F2/index.html

    cordova.file.applicationStorageDirectory => file:///data/data/<myAppName>/

    cordova.file.applicationDirectory => file:///android_asset/​

    If I attempt to save the file to cordova.file.applicationStorageDirectory (//data/data/<myAppName> or /data/data/<myAppName>/files/12590FAA-5EDD-4B12-856D-F52A0A1599F2/ I get an INVALID_MODIFICATION_ERR.

     

    What I am trying to achieve is to download the relevant file, save it to the device and be able to access via my application e.g. ​render the contents of a html file via the application.

     

    Thanks Mark.

  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 03 Nov 2015 Link to this post

    Hi Mark,

    As I understand you use the Cordova Plugin File. Referring to its online documentation:
    - the applicationDirectory seems to only suggest Read rights.
    - the applicationStorageDirectory seems to offer both Read and Write rights.
    - the dataDirectory have both Read and Write rights.

    An INVALID_MODIFICATION_ERR will be raised if the modification requested is not allowed. I am not sure how have you done you implementation. Would you try the approach suggested from the following blog? Does the same error pop up if you try writing in the dataDirectory instead?

    If the issue still persists, in order to be able to advice you further, may I ask you to share the exact implementation you have? 

    Looking forward to hearing from you.

    Regards,
    Dimitrina
    Telerik
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
  3. marko
    marko avatar
    20 posts
    Member since:
    Oct 2006

    Posted 03 Nov 2015 in reply to Dimitrina Link to this post

    Dimitrina,

     

    Thanks for the info, I resolved the issue by NOT using the sample code in the file plugin and simply rewrote it a different way. I was able to get to the directpry correctly by combining cordova.file.applicationStorageDirectory and window.location.href to get the app GUID ( or at least that is what it appears to be).

     

    Many Thanks,

     

    Mark.

Back to Top