API는 앱 종료 이후에도 지속되고 백그라운드에서 실행되며 사용자가 애플리케이션을 닫거나 일시 중단한 경우에도 계속되는 고급 파일 다운로드 기능을 제공합니다. 플러그인에는 진행 상황 업데이트가 포함되어 있으며 주로 비디오, 음악, 대형 이미지와 같은 리소스에 대한 장기 전송 작업을 위해 설계되었습니다.
샘플 사용법
var fileName = "PointerEventsCordovaPlugin.wmv",
uriString = "http://media.ch9.ms/ch9/8c03/f4fe2512-59e5-4a07-bded-124b06ac8c03/PointerEventsCordovaPlugin.wmv";
// open target file for download
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getFile(fileName, { create: true }, function (targetFile) {
var onSuccess, onError, onProgress; // plugin callbacks to track operation execution status and progress
var downloader = new BackgroundTransfer.BackgroundDownloader();
// Create a new download operation.
var download = downloader.createDownload(uriString, targetFile);
// Start the download and persist the promise to be able to cancel the download.
app.downloadPromise = download.startAsync().then(onSuccess, onError, onProgress);
});
});Android의 내부 및 외부(SD 카드) 저장소
외부 저장소
런타임에 cordova.file.externalDataDirectory 디렉토리를 확인하세요.
window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function(dirEntry) {
dirEntry.getFile(fileName, { create: true }, function (targetFile) {
...
})
}, function(error) {...}) 해당 장치에는 외부 저장소가 없을 수도 있습니다. 이 경우 cordova.file.externalDataDirectory null 이 되므로 사용하기 전에 확인해야 합니다.
내부 저장소
런타임에 cordova.file.dataDirectory 디렉토리를 확인하세요.
window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(dirEntry) {
dirEntry.getFile(fileName, { create: true }, function (targetFile) {
...
})
}, function(error) {...})자세한 내용은 파일 플러그인 문제를 읽어보세요.
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#android-quirks.
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#configuring-the-plugin-optiona
지원되는 플랫폼
윈도우8
윈도우폰8
iOS 7.0 이상
기계적 인조 인간
특이한 점
애플리케이션이 백그라운드에 있을 때 다운로드 작업이 완료된 경우 애플리케이션이 활성화되면 onSuccess 콜백이 호출됩니다.
애플리케이션이 닫힐 때 다운로드 작업이 완료된 경우, 파일이 즉시 다운로드된 것처럼 동일한 URI에 대해 첫 번째 startAsync()가 호출된 직후 onSuccess 콜백이 호출됩니다.
동일한 URI에 대한 새 다운로드 작업은 새 다운로드를 트리거하는 대신 보류 중인 다운로드를 재개합니다. 지정된 URI에 대해 보류 중인 다운로드가 없으면 새 다운로드가 시작되고 다운로드가 완료되면 대상 파일이 자동으로 덮어쓰여집니다.
Android에서는 임시 다운로드 파일이 외부 저장소에 생성되므로(DownloadManager의 제한) 외부 저장소가 없으면 다운로드가 실패합니다.