Last active
August 29, 2015 14:22
-
-
Save impaler/e161f018fdcec09b0e06 to your computer and use it in GitHub Desktop.
winjs download a file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('download a file', device.platform, location.href); | |
function DownloadFile(uriString, fileName) { | |
try { | |
console.log("started"); | |
var applicationData = Windows.Storage.ApplicationData.current; | |
console.log("applicationData", applicationData.localFolder.path); | |
applicationData.localFolder | |
.createFileAsync(fileName, Windows.Storage.CreationCollisionOption.generateUniqueName) | |
.done(function (newFile) { | |
console.log("test") | |
var uri = Windows.Foundation.Uri(uriString); | |
var downloader = new Windows.Networking.BackgroundTransfer.BackgroundDownloader(); | |
download = downloader.createDownload(uri, newFile); | |
promise = download.startAsync() | |
.then(function () { | |
console.log("success"); | |
}, error, function () { | |
console.log("progress"); | |
}); | |
}, error); | |
} catch (err) { | |
error("error", err); | |
} | |
}; | |
function error(err) { | |
console.log('err', err); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment