Log in

View Full Version : File Upload - Large Files?



phb5000
04-21-2007, 09:01 PM
Hi,

When attempting to upload a file to my server (using the <input type="file" /> tag) I get a "The connection was reset" error in firefox.

However, this only happens when I attempt to upload larger files, roughly greater than 2 mb.

Is this a server limitation?

thetestingsite
04-22-2007, 01:32 AM
It could be a server limit, or it could be something else in the form or server-side script you use to upload the files. If you could post the rest of the code for your form as well as the server-side script, we could probably give you a better answer.

Hope this helps.

phb5000
04-22-2007, 12:10 PM
Form tag:
<form method="post" runat="server" enctype="multipart/form-data">

File input:
<input type="file" size="34" id="tbUpload" runat="server" />

C# server side file uploader


public static void UploadFile(HttpPostedFile file, string type, string destination, bool canOverwrite)
{
HttpPostedFile uFile = file;

if (uFile == null || uFile.ContentLength == 0 || uFile.FileName == "") throw new Exception("No file has been selected!");

if (type != "")
if (uFile.ContentType != type)
throw new ArgumentException("Type does not match! Allowed: " + uFile.ContentType);

int len = uFile.ContentLength;
byte[] data = new byte[len];

uFile.InputStream.Read(data, 0, len);

if (File.Exists(destination))
{
if (canOverwrite) File.Delete(destination);
else throw new Exception("File already exists!");
}

FileStream newFile = File.Create(destination);
newFile.Write(data, 0, data.Length);
newFile.Close();
}

deficit
04-23-2007, 12:23 AM
You might be timing out. You said it's when you try to upload files larger than 2MB, which obviously takes longer than when uploading smaller files. It's just a suggestion, but do you have a server or session timeout set?

phb5000
04-23-2007, 01:14 PM
After uploading my website to my host my uploading worked fine, so I guess it was just a local problem.

Thanks for the help anyways =)