JavaScript API

Included in the "Server Files" folder of the ExpeDat distribution package is a JavaScript library and sample HTML for automating web integration.

EXP.js JavaScript library implementing the functions described below.
EXP.html  Simple HTML example showing how EXP.js can be used.

The functions below can be used to create and activate an "expedat://" URL, allowing JavaScript developers to dynamically create ExpeDat downloads.

EXP_Get()

This function accepts all of the parameters of an ExpeDat download as a direct JavaScript call.

function EXP_Get( server, /* DNS or IP of ExpeDat server [REQUIRED] */ port, /* Port number of ExpeDat server */ path, /* Full path to the target file */ username, /* Username, null for anonymous, blank to prompt */ password, /* Password, null for anonymous, blank to prompt */ encrypt, /* True if content must be encrypted */ compress, /* True of content should be compressed */ urlonly, /* True if we should not activate the URL */ urlid, /* Optional id to receive the URL as .innerText */ errid /* Optional id to receive error message as .innerText */ )

Only the server parameter is required.  Any of the others may be null.

EXP_Get("dataexpedition.com",null,"tst/test1mb.dat",null,null,true,false,false,"url_div","error_div");

The call above will create and activate the following URL:

expedat://dataexpedition.com/tst/test1mb.dat?encrypt=1

On success, EXP_Get() copies the generated URL to urlid.innerText, writes "Success" to errid.innerText, and returns the value 0.

If an error occurs, urlid.innerText will be blanked, an error message will be written to errid.innerText and the value -1 returned.

EXP_Get_Form()

This simplified interface pulls its inputs from the given form.  It is intended for use in a form "onsubmit" event attribute or a similar form validation function.  (See the example at the bottom of the page.)

function EXP_Get_Form( thisform, /* The form object containing the above parameters */ urlid, /* Optional id to receive the URL as .innerText */ errid /* Optional id to receive error message as .innerText */ )

The EXP.html example file illustrates the use of this interface.  The function looks for form inputs with the following names.  Only exp_server is required.

exp_server DNS or IP of the ExpeDat server [REQUIRED].
exp_port Port number of the ExpeDat server.
exp_path Path prefix. A '/' will be appended
exp_file File name, will follow exp_path
exp_username  Username text.  If this element does not exist, an anonymous download will be attempted.  If the element is present but blank, MTPexpedat will prompt the user to enter a username.
exp_password  Password text.  If exp_username exists and this element is blank or does not exist, then MTPexpedat will prompt the user to enter a password.
exp_encrypt If this is a checkbox, then its "checked" property will determine whether encryption is enabled or disabled.  For any other type of input, its "value" property will be used to set "encrypt".
exp_compress If this is a checkbox, then its "checked" property will determine whether compresssion is enabled or disabled.  For any other type of input, its "value" property will be used to set "compress".
exp_urlonly If this is present and checked or not-false, then the URL will not be activated.

On success, the generated URL will be copied to urlid.innerText, "Success" will be copied to errid.innerText, and the value 0 returned.

If an error occurs, urlid.innerText will be blanked, an error message will be written to errid.innerText and the value -1 returned.

Note that the "onsubmit" form event attribute must return false to prevent the browser from trying to submit the form via HTTP.  For example:

<FORM onsubmit="EXP_Get_Form(this,'exp_url','exp_error'); return false;" action="">