Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Reference

(nextflipdebug5) #1
Networking | 135

The second argument provided to theFile.upload( )method
call is the name of the form field that contains the file data.


The third argument is a Boolean value that tells the upload
process if it should try a test before sending the actual file.
The test upload will POST approximately 10KB of data to
the endpoint to see if the endpoint responds. If the service
monitoring capabilities of the Adobe Integrated Runtime are
not being used, this is a good way to check for potential
failure of the process.


TIP
More than one great web application has been caught by
this subtlety before. If the server is expecting the file data
outright, then a test upload will almost assuredly cause
an error. If you intend to use the test facility, be sure that
your server code is prepared to handle the scenario.

function doProgress( event )
{
var pct = Math.ceil( ( event.bytesLoaded / event.
bytesTotal ) * 100 );
document.getElementById( "progress" ).innerText =
pct + "%";
}

TheEvent.COMPLETEevent is relatively straightforward in that
it signals the completion of the upload process. This is a
good place to perform any file system maintenance that
might otherwise need to be accomplished by the application.
An example would be removing the just-uploaded file from
the local disk to free up space. Another task that might be
accomplished in theEvent.COMPLETEhandler is to start the
upload of subsequent files:


<html>
<head>

<title>Background Upload</title>
<script type="text/javascript" src="AIRAliases.js">
</script>
Free download pdf