This is a migrated thread and some comments may be shown as answers.

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

4 Answers 163 Views
Apache Cordova
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Niall
Top achievements
Rank 1
Niall asked on 29 Oct 2015, 06:19 PM

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.

4 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 03 Nov 2015, 03:21 PM
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.

 
0
Niall
Top achievements
Rank 1
answered on 03 Nov 2015, 03:48 PM

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.

0
Kannan
Top achievements
Rank 1
answered on 16 Mar 2017, 12:28 PM
Hi,
 
Here i'm using Cordova Framework for converting HTML5 to APK.  The HTML5 code have supporting files  like docx,pdf,images,js,css.
 
Sample HTML Code:
<!DOCTYPE html>
<html>
<body>
<h1>This is Test App for Cordova</h1>
<a href="wordfile.docx">file</a>
</body>
</html>
 
When i execute the above code in browser and when i click File " wordfile.docx" linked in the page is getting downloaded in the system
 
Android App:
When i click the same file after conversion into APK using Cordova the link is not responding, please guide me to perform the above action in android.
0
Kannan
Top achievements
Rank 1
answered on 16 Mar 2017, 12:28 PM
Hi,
 
Here i'm using Cordova Framework for converting HTML5 to APK.  The HTML5 code have supporting files  like docx,pdf,images,js,css.
 
Sample HTML Code:
<!DOCTYPE html>
<html>
<body>
<h1>This is Test App for Cordova</h1>
<a href="wordfile.docx">file</a>
</body>
</html>
 
When i execute the above code in browser and when i click File " wordfile.docx" linked in the page is getting downloaded in the system
 
Android App:
When i click the same file after conversion into APK using Cordova the link is not responding, please guide me to perform the above action in android.
Tags
Apache Cordova
Asked by
Niall
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Niall
Top achievements
Rank 1
Kannan
Top achievements
Rank 1
Share this question
or