This example shows how to upload an image file to a file server and save it in a web friendly format. There are two parts to this - an HTML form which contains an file input box and an Active Server Page to decode the uploaded file and save it as something web friendly.


HTML for the form    

The HTML for your form should appear something like the following. Note that we are using a multipart encoding, something which is required if you are using the input file-type form element.

<form method="post" action="upload.asp" name="submit" enctype="multipart/form-data">
  Choose a file to upload:<br>
  <input type="file" name="filefield" size="40"><br>
  <input type="submit" name="submit" value="submit"><br>


Decoding the Data    

Your upload.asp page should contain code to decode the uploaded file and save it out in a web friendly format. First we find the physical path to the place we are going to save the file.

path = Server.MapPath("../images/picture.jpg")

Next we get the uploaded information out of the request. Under ASP we have to use the ABCUpload XForm object to do this because the standard Microsoft Request object does not support multipart forms.

Set xf = Server.CreateObject("ABCUpload4.XForm")
Set field = xf("filefield")(1)


Drawing the Data    

Finally we create a Canvas, draw the binary data straight onto it and save the result out in the location we identified earlier.

Set canvas = Server.CreateObject("ImageGlue7.Canvas")
canvas.DrawData field.Data, field.FileName, ""
canvas.SaveAs path, ""