cordova-plugin-file
cordova-plugin-file copied to clipboard
The downloaded file is only 0 KB
`$('#saveFile').bind('click', function download() { var data = generateCodeFile(); var blob = new Blob([data], { type: "application/json" }); if (window.cordova && cordova.platformId !== "browser") { document.addEventListener("deviceready", function() { var folderPath = cordova.file.externalCacheDirectory; window.resolveLocalFileSystemURL( folderPath, function(dir) { dir.getFile( "my.cube", { create: true }, function (file) { file.createWriter( function (fileWriter) { fileWriter.write(new Blob(['some file data'], { type: 'text/plain' }));
fileWriter.onwriteend = function () {
alert(blob)
};
fileWriter.onerror = function (err) {
alert("Unable to download2");
console.error(err);
};
},
function (err) {
// failed
alert("Unable to download3");
console.error(err);
}
);
},
function (err) {
alert("Unable to download4");
console.error(err);
}
);
},
function(err) {
alert("Unable to download5");
console.error(err);
}
);
});
} else {
saveAs(blob, "my.cube");
}
});`