03.05.2013 Views

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The File<strong>Reference</strong>.upload() <strong>and</strong> File<strong>Reference</strong>.download() functions are<br />

nonblocking. These functions return after they are called, before the file transmission is<br />

complete. In addition, if the File<strong>Reference</strong> object goes out of scope, any upload or download<br />

that has not yet been completed on that object is cancelled upon leaving the scope. So, be sure<br />

that your File<strong>Reference</strong> object will remain in scope for as long as the upload or download<br />

could be expected to continue.<br />

The file is uploaded to the URL passed in the url parameter. The URL must be a server script<br />

configured to accept uploads. Flash Player uploads files using the HTTP POST method. The<br />

server script that h<strong>and</strong>les the upload should expect a POST request with the following<br />

elements:<br />

■ A Content-Type element of multipart/form-data<br />

■ A Content-Disposition element with a name attribute set to "Filedata" by default <strong>and</strong><br />

a filename attribute set to the name of the original file<br />

■ The binary contents of the file<br />

Here is a sample POST request:<br />

Content-Type: multipart/form-data; boundary=AaB03x<br />

--AaB03x<br />

Content-Disposition: form-data; name="Filedata"; filename="example.jpg"<br />

Content-Type: application/octet-stream<br />

... contents of example.jpg ...<br />

--AaB03x--<br />

To send POST parameters to the server, set the value of File<strong>Reference</strong>.postData to your<br />

parameters. You can send GET parameters to the server with the upload() call by appending<br />

parameters to the URL.<br />

If the file to be uploaded is bigger than approximately 10 KB, Windows Flash Player versions<br />

first send a test upload POST with zero content prior to uploading the actual file in order to<br />

verify that the transmission is likely to be successful. The second POST contains an actual file<br />

content. For smaller files, Flash Player does a single upload POST with the file to be uploaded.<br />

The Macintosh players currently do not do test upload POSTs.<br />

Note: If your server requires user authentication, only SWF files running in a browser—that<br />

is, using the browser plug-in or ActiveX control—can provide a dialog box to prompt the user<br />

for a user name <strong>and</strong> password for authentication, <strong>and</strong> only for downloads. For uploads that<br />

use the plug-in or ActiveX control, <strong>and</strong> for uploads <strong>and</strong> downloads that use the st<strong>and</strong>-alone or<br />

external player, the file transfer fails.<br />

590 <strong>ActionScript</strong> classes

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!