Phonegap API에는 원격 서버에서 다운로드 한 이미지를 저장하는 데 사용할 수있는 파일 시스템이 있습니다.
파일은 App Documents 폴더에 저장되므로 해당 경로 (각 설치마다 다른 경로)를 찾아 파일을 로컬로 저장하고 경로를 localstorage에 저장해야합니다. 여기
는 코드가 있습니다 첫째 snippet-과 운동을하기 위해 로컬 경로를 dummy.html 파일을 저장입니다 -
가
function downloadFile(webURL,webFilename){
window.requestFileSystem(
LocalFileSystem.PERSISTENT, 0,
function onFileSystemSuccess(fileSystem) {
fileSystem.root.getFile(
"dummy.html", {create: true, exclusive: false},
function gotFileEntry(fileEntry){
var sPath = fileEntry.fullPath.replace("dummy.html","");
var fileTransfer = new FileTransfer();
fileEntry.remove();
fileTransfer.onprogress = function(result){
var percent = result.loaded/result.total * 100;
percent = Math.round(percent);
console.log('Downloaded: ' + percent + '%');
};
fileTransfer.download(
webURL,
sPath + webFilename,
function(theFile) {
console.log("download complete: " + theFile.toURL());
showLink(theFile.toURL());
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code: " + error.code);
navigator.notification.alert('Seems to be an error downloading this background. Try again later.', null, 'Error', 'OK');
}
);
},
fail);
},
fail);
}
function showLink(localurl){
console.log(localurl);
}