Many problems with upload control, some work arounds.

This post has 10 replies

Not Ranked
Posts: 4
stevenmiles Posted: Mon Dec 8, 2008 @ 10:24 AM
I've been fighting this control for a while now. I've found work arounds to some issues, which I will share, but I've also found some fundamental flaws which should never have passed QA. I'm using 2008.2

Client problems

1. Client API doesn't work if you haven't set a file input template.
The client side API for adding, removing and clearing file from the input don't work if you haven't provided a file input template. The problem is the 'Render' method doesn't do anything if no template is provided.

Work around.
The render method can be forced to work by setting a secret boolean.

fileUploadControl.clearFiles();
fileUploadControl.addFile();
fileUploadControl.StaticContent = false;
fileUploadControl.Render();
fileUploadControl.StaticContent = true; 



3. Client event ProgressUpdate isn't fired.
Intellisense in the aspx page will show you a client event called ProgressUpdate. when a handler is provided it never executed.

Work around.
Ignore it, it's never looked at.

Server problems

4. Half uploaded temporary files aren't deleted
The UploadModule doesn't dispose of half upload files. the UploadedFileInfo class should implement IDisposeable. If you close the browser, do an abort or stop the upload in some other way you will not be able to delete the half uploaded file.

Work around.
Schedule a task to regularly delete files from the temp folder. I actually fixed the source but not everyone has that option.

5. Possible memory leak
The upload control adds an UploadInfo class to the application state when it is rendered to the form. If the file upload is not used to upload files then the no code will be executed to remove the the object from the application state. A post back of an a empty file upload doesn't remove this object either.

Work around.
Reboot server regularly.

Conclusion
The file upload control should have never been released in this state or should have at least been fixed in the last release. On the whole I am very disappointed with the controls I've used so far. The ideas are great but the implementation is rushed. In my opinion, the focus on broad platforms, new controls and lack of testing has compromised quality.
Top 10 Contributor
Posts: 6,424
hwan Posted: Wed Dec 10, 2008 @ 1:23 PM
Thanks for posting this, stevenmiles! Input like this is very valuable. Before I pass it along to the developers, can I verify that you were using Web.UI 2008.2.1240 SP2, the latest build of Web.UI? I believe we made some improvements with SP2, including improved abort() performance.
Not Ranked
Posts: 8
ryandanthony Posted: Tue Dec 16, 2008 @ 12:18 PM
Another Server Problem:

When you have a blank File Input on screen (InitialFileCount = "2", but only populate 1 of the upload fields) the UploadedFileInfo (via UploadedEventHandler) won't contain Extension, FileName, ContentType, etc.

The way around it is to remove the extra FileInputField on the client side prior to upload:
for (var i = 0; i < uploadControl.FileInputFields.length; i++)
{
    if (uploadControl.FileInputFields[i].value == "")
    {
        uploadControl.RemoveFileAt(i);
    }
}
uploadControl.Upload();
Not Ranked
Posts: 4
stevenmiles Posted: Wed Dec 17, 2008 @ 3:06 AM
Hi Hwan,

I've looked at the source for 2008.2 ASP.NET 3.5 SP2. From what I can see, Abort now seems to take the appropriate action. It restores the form, gets a new upload id, cancels scheduled check progress and prevents callback from firing an error event. Although the server problem still exists where the UploadedFileInfo in the UploadParser isn't disposed of properly meaning that the temporary files of the aborted upload aren't cleaned up.

To fix it, I made UploadedFileInfo disposable, kept the instance of the UploadedFileInfo used by the UploadParser on the current UploadInfo and changed dispose of UploadInfo to clean up this extra instance. This ensures that when the UploadInfo gets removed from the application state by the endrequest or error (happens on abort due to thread abort exception) handlers of the UploadModule all files are correctly deleted.

All other issues seem to still remain, including the memory leak. I'm in the process of applying my upload fixes to SP2 because I found Dialog.close() didn't work in 2008.2 either!! These are fundamental features, how do these problems get past QA?
Top 10 Contributor
Posts: 6,424
hwan Posted: Wed Dec 24, 2008 @ 8:01 AM
Thanks for following up. I have notified the developers of these issues and appreciate your patience!

OTD5981 - Client API doesn't work if a file input template isn't defined
OTD5982 - Client event ProgressUpdate is not raised
OTD5983 - Broken uploaded temporary files aren't deleted
OTD5984 - Possible memory leak due to UploadInfo in application state
Not Ranked
Posts: 15
hazosTAS Posted: Mon Feb 23, 2009 @ 11:06 AM
I upgraded to the latest ComponenetArt.WebUI and this
for (var i = 0; i < uploadControl.FileInputFields.length; i++)
{
    if (uploadControl.FileInputFields[i].value == "")
    {
        uploadControl.RemoveFileAt(i);
    }
}
uploadControl.Upload();

doesn't work anymore. Instead i get a "An error has occured during upload: non-negative number required. Parameter name: count" Any suggestions?
Not Ranked
Posts: 15
hazosTAS Posted: Mon Feb 23, 2009 @ 12:25 PM
Seems like there's something wrong with the removeFileAt function. I have an initialCount of 5, and if i upload 1 or 5 items it works. If i try two - four I get the error. If i manually remove the empty file inputs by using the removeFileAt it wont work either. I dont quite understand it.
Top 10 Contributor
Posts: 6,424
hwan Posted: Fri Feb 27, 2009 @ 12:28 PM
Try removing them in reverse order, as I suspect that removing them changes the indices.
Not Ranked
Posts: 15
hazosTAS Posted: Thu Mar 12, 2009 @ 8:22 AM
This is still an issue, no matter what order i remove the files. Does anybody have any suggestions?
Top 10 Contributor
Posts: 6,424
hwan Posted: Tue Mar 17, 2009 @ 11:32 AM
I tried this code and didn't see any issues:
WebFrom1.aspx (based on the Server-side Event example):
<script>
function doUpload(uploadControl)
{
	for (var i = uploadControl.FileInputFields.length-1; i>=0; i--)
	{
		if (uploadControl.FileInputFields[i].value == "")
		{
			uploadControl.RemoveFileAt(i);
		}
	}
	uploadControl.Upload();
}
</script>
....
<input type="button" value="doUpload" onclick="doUpload(Upload1)" />

I tested this with Web.UI 2008.2.1267.
Top 500 Contributor
Posts: 20
dforney Posted: Mon Dec 12, 2011 @ 12:02 AM
Have these issues been addressed in the 2010 version? I would like to use this control but I am also seeing the issue with RemoveFileAt in my current implementation and I am very concerned that these issues listed above are also still problems. 
Page 1 of 1 (11 items)