ExposureRoom Home
  Log in Sign Up
Shiv's Website
Shiv Kumar
United States
Friends: 70
Focused on : 2
 
       
                                                             

Upload Files From a Browser using an ISAPI

Not Rated YetNot Rated YetNot Rated YetNot Rated YetNot Rated Yet0votes
January 11, 2008 11:46 AM  Views:216   Favorited:0 Comments:0
Filed Under:  Programming
Tags:  Delphi, ISAPI
 

I have searched long and hard, high and low, for code that would allow me to do this in Delphi. Many people sent me to various web sites but never gave me a solution. No code, just the how-to. From the Microsoft site it was easy to find out the how-to, but obviously there was no code sample for the Delphi programmer.

 

It took me 2 full days to get this going. An extremely long time to be able to something so simple in Delphi. Well, simple, once you've figured it out and got it to work!

 

The code presented works and has no limitation on file size that can be uploaded. One could however optimize the code and clean it up a bit. I'd personally be interested in suggestions to improve the code from a resource/performance standpoint. Please email me with your tried and tested code.

 

Using the ISAPI application.

To be able to upload a file from a browser (client) to the web server, the HTML form needs to have the enctype set the multipart/form-data.

 

 

You can download the project file below to check out the code. The default action of the ISAPI will generate the HTML form suitable for file uploads. Once you compiled the project, you should see the file FileUpload.dll in C:\inetpub\scripts folder (set in the project options).

 

In your web browser, type in the URL http://mydomain/scripts/fileupload.dll

 

This should present you with the File Upload HTML Form. Browse to the required file and then click on the Send Button.

The file will be saved with the same name but in the C:\inetpub\scripts folder (set in the application).

 

Known Issues

I have noticed that files larger than 48K (this is when you have to use the Request.ReadClient method) the Request.ReadClient method takes one hell of a long time to return (I'm using D5 Win2000 and IIS 5.0). It does return eventually and everything works fine after that. I'd be interested in a "fix" for this or even a good explanation.

 

Wayne Niddery, sent me an email with the explanation for the delay. The reason is that in the code I was reading past the actual file size. The ReadClient method is supposed to return a -1 when there is nothing more to read. It does, but after a very long time. Wyne suggested I read only the actual file size. So I implemented the change and it worked perfectly. Thank you Wyne !

The modified project is available for download.

Comments have been Disabled for this post





Menus

Theme

Privacy Policy  |  Terms Of Service  |  Contact Us  |  Support  |  Help/FAQs  |  News