I have a custom web part in a sandbox solution. Inside of the web part I have added an <input type="file" />. Upon postback I read the file using HttpContext.Current.Request.Files and save the file in a document library.
The web part itself lives inside of a custom aspx as a <WebPartPages:SPUserCodeWebPart>. The aspx is deployed as a module and there is no master-page. The only markup in the aspx, except for the web-part is
<form method='post' runat="server" action="FileUploadPage.aspx" enctype="multipart/form-data">
and an <SharePoint:FormDigest> control.
This mechanism works fine when uploading small files. However, if the file being uploaded is larger than 80KB, the web part fails with the dreaded error message:
"Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred."
This exception cannot be caught via a catch statement and Fiddler tells me that the server returns a regular 200 success response containing the above error message. Also, if I attach a debugger to the web part code, the code is never hit. So, it's not an http error but rather an error that occurs between the moment the POST arrives on the server and the code-behind of the web part is executed.
My only explanation of this error is that there is some arbitrary limit to the size of the http request that you can post in custom aspx pages.
Is there another way of doing a custom file upload? I have considered uploading the file in chunks using AJAX. But I haven't found a way to partially upload a file in a document library.