Pure ASP File Upload


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

by Jacob Gilley

As a regular to ASP 101, I feel it neccesary to give a little back to the site that keeps me on top of things in the world of ASP. And so, I give you the FileUploader ASP Library. In a nutshell, the FilerUploader library is simply a single ASP include that provides an object-oriented approach to getting files from Internet clients.

I have seen numerous "pure ASP" upload solutions, some you even had to purchase, that did the job, but required you to wade through pages of code just to see how things worked. Then there are the COM components that you can buy that do what you want and more, but cost an arm and leg to obtain. What I wanted was something simple, centralized, easy to use and FREE! The FileUploader Library was the solution and now I want to share my work with fellow developers.


The library consists of two VBScript classes: FileUploader and UploadedFile. The FileUploader is the top-level object in the model and is the only one that you will need to instantiate.

Here is how to do it: (this assumes that you have included "upload.asp")

  Dim MyUploader
  Set MyUploader = New FileUploader


Now once your FileUploader object is initialized, you can begin recieving the uploaded data from the client by a single call to the Upload() method.


Or, since Upload() is the default method, you can use a shortcut and start the upload process like this: (Use one or the other, not both)


Once that is complete, you can begin access and saving the file to your hard-drive or to a database. The uploaded files are accessed through the Files Collection of the FileUploader object. The Files Collection is a set of UploadedFile objects that represent each file uploaded.

Here is an example of how to enumerate the Files Collection and write each uploaded files' information to the browser:

  Dim File
  For Each File In MyUploader.Files.Items
    Response.Write "File Name:" & File.FileName
    Response.Write "File Size:" & File.FileSize
    Response.Write "File Type:" & File.ContentType


Here is an example of how to access a specific file in the Files Collection using the HTML file input element name as the Index:

  Response.Write "File Name:" & MyUploader.Files("file1").FileName
  Response.Write "File Size:" & MyUploader.Files("file1").FileSize
  Response.Write "File Type:" & MyUploader.Files("file1").ContentType


For simplicity sake, I will be the using the For Each...Next variation for the following samples. Now, all the files are uploaded and its time to put them somewhere. There are two places you can save the uploaded files...on your hard-drive or to a database.

Here is how to save the files to disk:

  Dim File
  For Each File In MyUploader.Files.Items
    File.SaveToDisk "C:\UploadedFiles"


And how to save to a database: (Replace "MyUploadTable", "CONNECT STRING.." and field names accordingly)


  Dim RS
  Dim File

  Set RS = Server.CreateObject("ADODB.Recordset")
  RS.Open "MyUploadTable", "CONNECT STRING OR ADO.Connection", 2, 2

  For Each File In MyUploader.Files.Items

    RS("filename") = File.FileName
    RS("filesize") = File.FileSize
    RS("contenttype") = File.ContentType

    File.SaveToDatabase RS("filedata")



I think that should just about cover everything. I hope this helps out and that you found my blathering somewhat interesting. If you have any questions or comments about this article or the code provided, feel free to email me. (avis7@airmail.net)

You can download the library and sample files below (4 KB).

p34c3 +0 4|| c0d3rz!

Update: Pure ASP File Upload Gets a Speed Boost

Jacob Gilley's Pure ASP File Upload is an effective, free method for uploading user files to your server. Although well implemented, I found that the file I/O needed improvement. Concatenation is quite slow in VBScript and it was actually faster to write a single byte at a time to the disk than to concatenate the file prior to saving.

Here Robbert Nix's improved concatenation algorithm comes to the rescue. I stumbled upon this algorithm when searching for performance enhancements in VBScript. Essentially Nix's code allows Gilley's Pure ASP File Upload to return to concatenation as a viable method for preparing the file prior to saving.

Two files are included with this implementation: upload.asp and buffering.inc. These files are meant to be incorporated with the existing distribution for Gilley's Pure ASP File Upload. The upload.asp file replaces the existing version and the include file buffering.inc is used to improve upload time.

Note: if you replace your existing version of upload.asp you must also copy buffering.inc to the same directory! No changes in existing upload pages are required to take advantage of this upgrade.

Gilley's Pure ASP File Upload files are needed and can be found above.

You can download the updated upload.asp and new buffering.inc in a zip file, fileuploader_buffering.zip, below (3.4 KB)

Do Many Things ... Well

Update: Even Faster Yet...

It seems that the update above caught the atention of one of our other authors... here's his message:

Hello. I already have a few articles posted on your website so far. I just got your newsletter concerning ASP uploads: Update: Pure ASP File Upload Gets a Speed Boost

While this may be faster - it is still very slow. I have found a way around this in the past and had posted my findings on planet source code at:


I am including the upload_files_without_com_v2.zip file (below) (28 KB) for you to go over and review with this message. The zip file also includes a screen shot to demonstrate the simplicity of the code, and also contains a working sample. It is commented well and uses classes for a more object-oriented approach. Rather then converting each character between ansi and unicode 1 at a time - this class calls the ADODB Stream object to do it all at once. ADO 2.5+ is required along with vbScript 5.0+

I have had very good reviews posted by others about this code on planet source code.

Allowing files to be translated quicker allows users to post larger files before the server times out. Happy Coding!


Update: Listing the Files That Have Been Uploaded

Our "Pure ASP File Upload" article has been getting update after update recently and here's one more. When we left it last, updated files were getting entered into a database. This update brings a simple little script to display a list of those files. Here's the message:

I just wanted to share some code I came up with to display all the files uploaded to the database using Lewis Moten's code (which was very useful and fairly easy to use). I needed to create an area on our company website where the advertising and sales staff could share files back and forth easily but I found that Lewis's code only took care of the upload part. We needed to be able to view all the files as well.

Well, here it is. It just runs through the database until it reaches End Of File (EOF) and displays the filenames as links to that file. It requires Lewis Moten's DataFile.asp file to work but there is no need to modify it. The modifications have been made in my code to make it work with that file as is.

Dim oConn
Dim oRS
Dim sSQL
Dim lngFileID

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" _
	& Server.MapPath("db\Files.mdb"))

sSQL = "SELECT FileID, FileName, Date FROM Files " _
	& "ORDER BY Date desc, FileName"

Set oRS = oConn.Execute(sSQL)

If oRS.EOF Then
	Response.Write("<font face=arial size=2><b>There are " _
		& "currently no files in the database.</b></font><br>")
	Do While NOT oRS.EOF
		lngFileID = oRS("FileID").Value
		Response.Write("<a href=DataFile.asp?FileID=" _
			& lngFileID & " target=_blank>" _
			& oRS("FileName").Value & "</a><br>")
End If

Set oRS = Nothing
Set oConn = Nothing

The only thing that might throw people is that I've changed the path to the database since mine is stored in the "db" directory on my server therefore the path is db/Files.mdb. I've also included an ORDER BY clause in my sql statement to display the files from newest to oldest and then in alpha order by filename. This code can be placed anywhere on your page that you want the files displayed. You can also set it up to display the files in multiple columns across the page in a <table> instead of one long column down the page but you need to add additional "If NOT oRS.EOF Then" code before each new table cell. I've used this code on a page with other asp code so if you use it by itself you'd need to add the Option Explicit statement at the top.

Thanks for the great asp resource. Many of my peers have recommended your site to me when I've had questions about developing asp solutions for various things on my websites. Have a great day.

Bryan Hovey

Thanks Bryan... I'm sure you're not the only one who needs this functionality. A number of our users are sure to find this helpful.

About the Author

From ASP101

Articles originally posted on ASP101.com



  • Programmer Analyst

    Posted by Marc LeLacheur on 02/21/2018 02:11pm

    I've discovered while trying to use this for a multiple file upload that there is a flaw with the clsUpload Fields property. If you try to access the Field by an Index number it will always return an New Field object. To correct this, I've done the following: Edit clsUpload.asp Cut Lines 445 & 446 Go to Line 443, add an ELSE before the END IF, and paste those 2 Lines inside. Add another new line before the END IF, and add "Exit Property" there too. With that the Fields property should work with Indices the same as using the Field Name.

  • Incredible that classic ASP is in use in these days

    Posted by nonlinearly on 07/28/2017 08:16am

    Incredible that classic ASP is in use in these days... But if we think that there is a lot lot lot of code written in asp from past and has to be maintain then it is obvious.

  • do we need to download library

    Posted by madhur on 03/28/2017 05:58pm

    do we need to download FileUploader Library ? if yes then from where i can download in order to upload file. Thanks

  • Get file input name or id

    Posted by Chad on 03/02/2017 04:15pm

    Hello Jacob, So far the FileUploader is working well to save to database, but I'd like to get a hold of the name or id of the file input it came from so I can identify which upload I'm saving. For instance, if I have fileInput1 as the name, I'd like to get a hold of that name. So far I'm only able to see the name of the file being uploaded. Is there a way to get at this?

  • change in file encoding after Upload

    Posted by rachhek shrestha on 11/13/2016 11:54am

    Hello, I have a file which has an encoding Shift-JIS. It contains Japanese characters. Whenever I use this library to upload that file, my characters gets all garbled. What should I do? Thanks,

  • To database - files larger than 10mb

    Posted by Jose Mendes on 11/02/2016 11:00pm

    Hello. I'm using this script to upload files to a Sql Server 2000 table, using IIS 5.1 (windows xp sp3). It works fine with files up to 10 or 12 Mb but with files larger than that I get an error: Microsoft OLE DB Provider for SQL Server error '80004005' Unspecified error at the line where the recordset is updated. Can you please offer some advice?

  • Writing binary data out by the FileSystemObject stopped working recently

    Posted by Don Hughes on 03/22/2016 02:11pm

    Recently our file upload code, based partially on techniques invented by Jacob Gilley stopped working. This was because some stricter validations now seem to be taking place. The code would create a 0 byte file but then fail to write to it - probably because a binary file produces bytes that aren't in the ASCII range. Attempting to fix this using an ADODB.Stream object led to the same problem for some strange reason. I then found Lewis Moten's code that gets around the problem in ADODB.Stream by type-casting the byte array through a Recordset object. I implemented something similar in our code and the problem was solved. The code you need is Private Function WashTheBytes(ByRef pbinBinaryData) Dim lobjRs Dim llngLength Dim lbinBuffer llngLength = LenB(pbinBinaryData) Set lobjRs = Server.CreateObject("ADODB.Recordset") Call lobjRs.Fields.Append("BinaryData", adLongVarBinary, llngLength) Call lobjRs.Open() Call lobjRs.AddNew() Call lobjRs.Fields("BinaryData").AppendChunk(pbinBinaryData) ' Update / Convert Binary Data to the Byte Subtype Array that the ADODB.Stream is expecting Call lobjRs.Update() ' Request binary data and save to stream lbinBuffer = lobjRs.Fields("BinaryData").GetChunk(llngLength) ' Close recordset Call lobjRs.Close() ' Release recordset from memory Set lobjRs = Nothing ' Return Bytes GetBytes = lbinBuffer End Function Then you can oStream.Write WashTheBytes(FileData) I hope this helps someone.

  • Using an interstitial page?

    Posted by James on 12/19/2015 01:38am

    Suppose we need to select a file along with filling out a form, and need to insert an interstitial page for the user to review their entries, before executing the upload? How would we persist the file all the way to the upload code?

  • www-urlencoded

    Posted by Gaz on 10/21/2015 11:18pm

    Hi, Is there anyway to capture x-www-urlencoded data - I know its slower but is the only format available to me due to restrictions! Thanks,

  • Over write the existing file - SaveAs

    Posted by sivasai on 02/03/2015 02:17pm

    Hi The file upload is working fine. But then when i am trying to edit and upload new file in the place of existing file how can handle this. Can you please help me on this?

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date