Örnek kod cordova dosyası ve dosya aktarım eklentisi kullanarak cihazdaki pdf dosyası yazmak için:
var fileTransfer = new FileTransfer();
if (sessionStorage.platform.toLowerCase() == "android") {
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, onFileSystemSuccess, onError);
} else {
// for iOS
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onError);
}
function onError(e) {
navigator.notification.alert("Error : Downloading Failed");
};
function onFileSystemSuccess(fileSystem) {
var entry = "";
if (sessionStorage.platform.toLowerCase() == "android") {
entry = fileSystem;
} else {
entry = fileSystem.root;
}
entry.getDirectory("Cordova", {
create: true,
exclusive: false
}, onGetDirectorySuccess, onGetDirectoryFail);
};
function onGetDirectorySuccess(dir) {
cdr = dir;
dir.getFile(filename, {
create: true,
exclusive: false
}, gotFileEntry, errorHandler);
};
function gotFileEntry(fileEntry) {
// URL in which the pdf is available
var documentUrl = "http://localhost:8080/testapp/test.pdf";
var uri = encodeURI(documentUrl);
fileTransfer.download(uri, cdr.nativeURL + "test.pdf",
function(entry) {
// Logic to open file using file opener plugin
},
function(error) {
navigator.notification.alert(ajaxErrorMsg);
},
false
);
};
cihazın yerel depolama dosyayı kaydetmek kullanımı dosya transferi eklentisi veya özel kod kullanabilirsiniz. Aşağıdaki koddaki dosya oluşturma bölümünün altındaki örnek kodu kontrol edin: http://stackoverflow.com/questions/36037359/unable-to-delete-file-using-cordova/36038741#36038741 – Gandhi
Cevabınız için teşekkürler. Bu eklentiyi yükledim, ancak bu örnekte dosyayı saklamak için kullanmam gerekeni bilmiyordum. Base64 kodu? Blob? Ben yeniyim ve bunu yapıyorum. – Steph8
lütfen cevap bölümümdeki örnek kodu bulun. Umarım yardımcı olur. Cevabınız için – Gandhi