0
votes

If you put a asp:FileUpload control on a page, browse to a file, and then submit the form. is the file uploaded to the server when you submit the form?

I have seen loads of examples of file uploads where the file is passed to a filestream and uploaded.

I don't understand what is happening when. After you click your Upload button, the code is being executed on the server. So the file (file name? file path?) supplied by the FileUpload control using FileUpload.PostedFile (or the httpFileCollection) ... is this uploaded when the form is submitted? How can the server gain access to the file on the client machine so it can be uploaded using a filestream.

I don't get it. I keep reading that the filestream passes (can pass) the data in chunks - helping to bypass restrictions on file size etc. but, as I said above, when/how is the file uploaded to the server?

2

2 Answers

1
votes

The <asp:FileUpload> control renders an <input type="file">, and sets the form's content type to multipart/form-data.

When the browser submits a <form> with an <input type="file">, it will send the entire file to the server in the HTTP POST (this is part of the content-type).

1
votes

When you click upload, the html form is submitted and a post request is send to the server.

It does not actually send you a "file" object of some kind that you can directly store, just the content of the file in bytes and some metadata, like the filename.

On the server, you have to handle this request: You have to read the bytes into an actual file to properly store it.

In the example that you mention, this is what the HttpPostedFile is used for.