From f6736d9150c234c4667d97057e861791b6b97853 Mon Sep 17 00:00:00 2001 From: russa Date: Wed, 16 Sep 2020 18:37:15 +0200 Subject: [PATCH] added usage description for abort() --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/README.md b/README.md index c656f12..e9cc16b 100644 --- a/README.md +++ b/README.md @@ -404,6 +404,46 @@ cordova.plugin.http.downloadFile("https://google.com/", { }); ``` +### abort +Abort a HTTP request. Takes the `requestId` which is returned by [sendRequest](#sendRequest) and its shorthand functions ([post](#post), [get](#get), [put](#put), [patch](#patch), [delete](#delete), [head](#head), [uploadFile](#uploadFile) and [downloadFile](#downloadFile)). + +If the request already has finished, the request will finish normally and the abort call result will be `{aborted: false}`. + +If the request is still in progress, the request's `failure` callback will be invoked with response `{status: -8}`, and the abort call result `{aborted: true}`. + +:warning: Not supported on iOS. + +```js +// start a request and get its requestId +var requestId = cordova.plugin.http.downloadFile("https://google.com/", { + id: '12', + message: 'test' +}, { Authorization: 'OAuth2: token' }, 'file:///somepicture.jpg', function(entry) { + // prints the filename + console.log(entry.name); + + // prints the filePath + console.log(entry.fullPath); +}, function(response) { + // if request was actually aborted, failure callback with status -8 will be invoked + if(response.status === -8){ + console.log('download aborted'); + } else { + console.error(response.error); + } +}); + +//... + +// abort request +cordova.plugin.http.abort(requestId, function(result) { + // prints if request was aborted: true | false + console.log(result.aborted); +}, function(response) { + console.error(response.error); +}); +``` + ## Browser support This plugin supports a very restricted set of functions on the browser platform.