binary file upload using HTTP


I was looking into how to achive a file upload using http. I found an interesting example @ 

As you can see it allows the client to upload a gif file which it displays. I am interested in how this works on the client side. I looked at the source code and could not work it out.

Where is the code telling the browser to open the windows "file open dialog box" and where is the code to perform a URL encode on the data? I assume thats what it does.

I also copied the source and ran it on my local machine, when I did this the "browse" for a file button vanished (I never saw the code for it in the original), where did it come from?

I'm confused.... how does it work?

Also Is there a limit to the file size you can upload?

Thanks, Andy
Who is Participating?
BigRatConnect With a Mentor Commented:
The input form must POST the data and the type is called "multipart-form". You can find a spec of what the server sees (or what the browser sends) by searching for this term and downloading the RFC (whose number escape me for the moment).
   The browser "invents" a sequence of characters which DOES NOT OCCUR in the file data, eg: xvtyfghstegsjshbe. It then sends

<data from the file>

as well as the other (if any) form fields. You in your cgi must separate all this out and recontruct the file.

There is no limit that I have found on uploading. My app uploads files of around 11MB. I do all of this in C without any special objects. VB wraps all this up in objects, of which I have no experience.
i can atleast help you out with the file dialog showing up .. to get that use something like this <input type=file name=filenm size=20 accept="image/*">

This kind of form uploads files for me with no problem

<form enctype="multipart-form/data" method=POST action="/somepath/upload.asp" name=main>
<input type=file name=TheFile size=50>

In this way browser reads the file, encodes it using MIME encoding and sends to the action URL, where it may be extracted using some COM object, or cgi-script.
andyknottAuthor Commented:
Thanks all of you for your help. Its a shame points can't be divided between several experts.

It was hard to decide who's answer to except. Bigrat gave the general description I required.

Thanks again
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.