Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. function fileDownload(dirName, fileURL, fileName) {
  2.  
  3. window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
  4.  
  5. window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, fsAccess, fsFail);
  6.  
  7. function fsAccess(fileSystem) {
  8.  
  9. fileSystem.root.getDirectory(dirName, { create: true, exclusive: false }, dirReady, dirFail);
  10.  
  11. }
  12.  
  13. function fsFail() {
  14.  
  15. console.log("Filesystem Access Failed");
  16.  
  17. }
  18.  
  19. function dirFail() {
  20.  
  21. console.log("Directory Access Failed");
  22.  
  23. }
  24.  
  25. function dirReady(entry) {
  26.  
  27. window.appRootDir = entry;
  28.  
  29. console.log(JSON.stringify(window.appRootDir));
  30.  
  31. var fileTransfer = new FileTransfer();
  32.  
  33. fileTransfer.download(
  34. fileURL,
  35. window.appRootDir.nativeURL + fileName,
  36. function (theFile) {
  37. console.log("download complete: " + theFile.toURL());
  38. },
  39. function (error) {
  40. console.log(JSON.stringify(error));
  41. }
  42. );
  43.  
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement