Skip to content

Commit 43b65fa

Browse files
committed
docs: extend downloadFile example code
1 parent 4844578 commit 43b65fa

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

README.md

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -414,21 +414,32 @@ cordova.plugin.http.uploadFile("https://google.com/", {
414414
```
415415

416416
### downloadFile<a name="downloadFile"></a>
417-
Downloads a file and saves it to the device. Takes a URL, parameters, headers, and a filePath. See [post](#post) documentation for details on what is returned on failure. On success this function returns a cordova [FileEntry object](http://cordova.apache.org/docs/en/3.3.0/cordova_file_file.md.html#FileEntry).
417+
Downloads a file and saves it to the device. Takes a URL, parameters, headers, and a filePath. See [post](#post) documentation for details on what is returned on failure. On success this function returns a cordova [FileEntry object](http://cordova.apache.org/docs/en/3.3.0/cordova_file_file.md.html#FileEntry) as first and the response object as second parameter.
418418

419419
```js
420-
cordova.plugin.http.downloadFile("https://google.com/", {
421-
id: '12',
422-
message: 'test'
423-
}, { Authorization: 'OAuth2: token' }, 'file:///somepicture.jpg', function(entry) {
424-
// prints the filename
425-
console.log(entry.name);
426-
427-
// prints the filePath
428-
console.log(entry.fullPath);
429-
}, function(response) {
430-
console.error(response.error);
431-
});
420+
cordova.plugin.http.downloadFile(
421+
"https://google.com/",
422+
{ id: '12', message: 'test' },
423+
{ Authorization: 'OAuth2: token' },
424+
'file:///somepicture.jpg',
425+
// success callback
426+
function(entry, response) {
427+
// prints the filename
428+
console.log(entry.name);
429+
430+
// prints the filePath
431+
console.log(entry.fullPath);
432+
433+
// prints all header key/value pairs
434+
Object.keys(response.headers).forEach(function (key) {
435+
console.log(key, response.headers[key]);
436+
});
437+
},
438+
// error callback
439+
function(response) {
440+
console.error(response.error);
441+
}
442+
);
432443
```
433444

434445
### abort<a name="abort"></a>
@@ -445,12 +456,15 @@ If the request is still in progress, the request's `failure` callback will be in
445456
var requestId = cordova.plugin.http.downloadFile("https://google.com/", {
446457
id: '12',
447458
message: 'test'
448-
}, { Authorization: 'OAuth2: token' }, 'file:///somepicture.jpg', function(entry) {
459+
}, { Authorization: 'OAuth2: token' }, 'file:///somepicture.jpg', function(entry, response) {
449460
// prints the filename
450461
console.log(entry.name);
451462

452463
// prints the filePath
453464
console.log(entry.fullPath);
465+
466+
// prints the status code
467+
console.log(response.status);
454468
}, function(response) {
455469
// if request was actually aborted, failure callback with status -8 will be invoked
456470
if(response.status === -8){

0 commit comments

Comments
 (0)