Tank2005
Tank2005

Reputation: 909

How to use FileTransfer.download on Android

I use Phonegap 1.9.0 on Android, but there are few samples on the web, so I worry about download of a file.

var ft = new FileTransfer();
ft.download(
    "http://www.something.com/test.zip",
    "test.zip", // <- Trouble 1
    function(entry) {
        alert("success");
    },
    function(err) {
        alert(err); // <- Trouble 2
    }
);

1.I don't understand the way of specifying a file path suitable for this argument. How should I specify a local path? Or is there any required Android.permission?
2.The message "Class not found" is shown. What is this cause?
3.What is the path in native Java of the downloaded file?

Upvotes: 4

Views: 12926

Answers (3)

Manjesh V
Manjesh V

Reputation: 1240

// This worked for me
var ft = new FileTransfer();
ft.download(
  "http://www.something.com/test.zip", // what u download
  "/sdcard/test.zip", // this is the filename as well complete url
  // fileSystem.root.toURL() + "test.zip",  use ios and others
  function(entry) {
    alert("success");
    alert(JSON.stringify(entry));

  },
  function(err) {
    alert(err);
    alert(JSON.stringify(err));
  }
);

You can check directory structure in ADT Eclipse DDMS Perspective -> File Explorer

Upvotes: 1

dajver
dajver

Reputation: 250

var ft = new FileTransfer();
ft.download(
    "http://www.something.com/test.zip", // what u download
    "", // this is dir which u download, right now, it will download to mnt/sdcard/
    function(entry) {
        alert("success");
    },
    function(err) {
        alert(err); 
    }
);

Upvotes: 0

oshevans
oshevans

Reputation: 116

Yeah the Cordova/Phonegap docs are very lite on real world examples!

  1. Simon Mac Donald has a great post on downloading: http://simonmacdonald.blogspot.co.uk/2012/04/sorry-for-being-gone-so-long-vacation.html If you want to download multiple files, check out his gist: https://gist.github.com/3835045

  2. I think FileTransfer is only available on the device (maybe the emulator?), but I also get this error in the browser - maybe someone else can chip in with an explanation/workaround for this one.

  3. This will depend on the platform, but it can be found with FileSystem.root.fullPath. If you are appending filenames, you'll need to add a slash.

Upvotes: 1

Related Questions