download

Http

Sends a GET request to the specified url and downloads the response to a file.

$m.download("http://www.cloudpact.com", function(response){

   if(response.code == 200 && response.result.data){

      $m.toast("Download successful.");

   } else{

      $m.toast(response.error.message);

   }

});

Syntax

        $m.download(url , file[, fp_callback])

        $m.download(url , file[, options, fp_callback])

Parameters

Url

string (required)

The url to which the request must be fired.

fp_callback

function (optional)

The function to invoke after the request has been executed. The function receives the response object which contains the following properties.

  1. code - {Number}. 0 if the request failed to fire due to malformed url or network error, otherwise the http status code sent by the server.
  2. result - {Object}. The result contains the following properties,
  1. headers - {Object}. The response headers received from the server.
  1. data - {String}. data - {Boolean}. true, if the response data received from the server and successfully written to the specified file; false, otherwise.

  1. error - {Object}. If code is 0, the error contains the properties,
  1. message - {String}. The error message.
  2. description - {String}. The error description in detail if any.

options

object (optional)  

Optional parameters object for the request. It can contain one or more of the following properties,

  1. headers - {Object}. The headers to be set for the request. Default value is {}.
  2. timeout - {Number}. The timeout of the request in milliseconds. If the response is not received from the server within timeout period, the request will be cancelled and a timeout error will be thrown. Default value is 30000.