cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "decagon (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (CB-11307) Can't create file with cordova.file.dataDirectory or cordova.file.cacheDirectory
Date Mon, 23 May 2016 15:35:12 GMT

     [ https://issues.apache.org/jira/browse/CB-11307?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

decagon updated CB-11307:
-------------------------
    Description: 
I'm trying to create and write to a file in cordova.file.dataDirectory
(file:///data/data/<package name>/files/) or cordova.file.cacheDirectory.

But without success on android 4.4.2 .
The code fails on :

or using : 
fs.root.getFile("myfile.txt", { create: true, exclusive: false }, function () {}, function
() {});


Example of code :

window.resolveLocalFileSystemURL(cordova.file.dataDirectory,
	function (directoryEntry) { // success
		directoryEntry.getFile('myfile.txt', { create: true },
			function (fileEntry) { //success

				fileEntry.createWriter(
					function (fileWriter) { // success

						fileWriter.onwriteend = function () {
							console.log("OK");
						};

						fileWriter.onerror = function (e) {
							console.log("Not OK");
						};

						// If data object is not passed in,
						// create a new Blob instead.
						if (!data) {
							data = new Blob([' '], { type: 'text/plain' });
						}

						data = JSON.stringify(data);
						var blob = new Blob([data], { type: 'text/plain' });

						fileWriter.write(blob);
					},
					function (e) { // error
						console.log(e);
					}
				);
			},
			function (e) { // error
				console.log(e);
			}
		);
	},
	function (e) { // error
		console.log(e);
	}
);

directoryEntry.getFile doesn't work.

However, it works on Android 6


  was:
I'm trying to create and write to a file in cordova.file.dataDirectory
(file:///data/data/<package name>/files/) or cordova.file.cacheDirectory.

But without success on android 4.4.2 .
The code fails on :

window.resolveLocalFileSystemURL(cordova.file.dataDirectory,
	function (directoryEntry) { // success
		directoryEntry.getFile('myfile.txt', { create: true },
			function (fileEntry) { //success

				fileEntry.createWriter(
					function (fileWriter) { // success

						fileWriter.onwriteend = function () {
							console.log("OK");
						};

						fileWriter.onerror = function (e) {
							console.log("Not OK");
						};

						// If data object is not passed in,
						// create a new Blob instead.
						if (!data) {
							data = new Blob([' '], { type: 'text/plain' });
						}

						data = JSON.stringify(data);
						var blob = new Blob([data], { type: 'text/plain' });

						fileWriter.write(blob);
					},
					function (e) { // error
						console.log(e);
					}
				);
			},
			function (e) { // error
				console.log(e);
			}
		);
	},
	function (e) { // error
		console.log(e);
	}
);
or using : 
fs.root.getFile("myfile.txt", { create: true, exclusive: false }, function () {}, function
() {});



However, it works on Android 6



> Can't create file with cordova.file.dataDirectory or cordova.file.cacheDirectory
> --------------------------------------------------------------------------------
>
>                 Key: CB-11307
>                 URL: https://issues.apache.org/jira/browse/CB-11307
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Plugin File
>         Environment: Visual studio 2015 with cordova, Android 4.4.2
>            Reporter: decagon
>
> I'm trying to create and write to a file in cordova.file.dataDirectory
> (file:///data/data/<package name>/files/) or cordova.file.cacheDirectory.
> But without success on android 4.4.2 .
> The code fails on :
> or using : 
> fs.root.getFile("myfile.txt", { create: true, exclusive: false }, function () {}, function
() {});
> Example of code :
> window.resolveLocalFileSystemURL(cordova.file.dataDirectory,
> 	function (directoryEntry) { // success
> 		directoryEntry.getFile('myfile.txt', { create: true },
> 			function (fileEntry) { //success
> 				fileEntry.createWriter(
> 					function (fileWriter) { // success
> 						fileWriter.onwriteend = function () {
> 							console.log("OK");
> 						};
> 						fileWriter.onerror = function (e) {
> 							console.log("Not OK");
> 						};
> 						// If data object is not passed in,
> 						// create a new Blob instead.
> 						if (!data) {
> 							data = new Blob([' '], { type: 'text/plain' });
> 						}
> 						data = JSON.stringify(data);
> 						var blob = new Blob([data], { type: 'text/plain' });
> 						fileWriter.write(blob);
> 					},
> 					function (e) { // error
> 						console.log(e);
> 					}
> 				);
> 			},
> 			function (e) { // error
> 				console.log(e);
> 			}
> 		);
> 	},
> 	function (e) { // error
> 		console.log(e);
> 	}
> );
> directoryEntry.getFile doesn't work.
> However, it works on Android 6



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


Mime
View raw message