|
So what is File Upload and how does it work? File
Upload or HTTP upload allows your visitors to send files to your
web server using standard forms. In the same way that there are
form elements that allow you to enter text and others that allow
you to choose items from a list there is a form element that allows
you to choose a file.
So what does a File Upload form element look
like? Well here's a small and nonfunctional form containing a file
input field.
File Upload was not supported in Internet
Explorer 3.0 but was soon afterwards added in version 3.02. It is
available in Netscape Navigator from version 2.02 onwards. So the
great advantage of HTTP upload is that upload facilities are
standard on virtually any browser that will come to your web
site.
So what does the HTML look like? Well, much like
any other piece of form HTML. Here's the code for the above.
<form method="post" action="file-upload-1.htm"
name="submit" enctype="multipart/form-data">
<input type="file" name="fileField"><br><br>
<input type="submit" name="submit"
value="submit"><br>
</form>
There are only a couple of real differences. The
input type of the upload is 'file' rather than 'text'. The
'enctype' of the form is 'multipart/form-data'. Multipart form data
is an Internet standard (covered by RFC 1867) for sending lots of
different types of information over the Internet as one
bundle.
After the upload form has been submitted to the
server we have to get the server to extract the file from the
upload. You can do this using standard ASP.NET components but you
should bear in mind that file upload is not as simple as it might
seem. Just as one example, some browsers encode files before
transmitting them! Internet Explorer on MacOS uploads files encoded
as MacBinary to allow special Mac specific features to be
transmitted. While Mac browsers will normally make up only 10% of
your visitors, you should bear in mind your audience. In some
picture related industries like publishing you may find that this
proportion approaches 100%.
A related issue is that you can't really rely on
either the file name or the mime type of the file as provided to
you. Because of the cross platform nature of the industry a text
file may be named 'readme' or 'readme.txt' or even 'readme
10\10\99'. Because the mime type is determined by the browser it
could be anything from 'text/plain' to 'application/x-macbinary' to
something completely meaningless. You have to make decisions on a
case by case basis depending on what you are trying to do.
ABCUpload is designed to work around these
problems invisibly so that you don't have to worry about
them.
|