Error when using enctype="multipart/form-data"

D

Dylan Parry

Hi folks,

I’ve built a form to edit some database entries, and I’ve just added a
field to allow the user to upload an image for the entry. Everything
worked fine until I changed the form element to contain
enctype="multipart/form-data" so that the image actually gets uploaded.

Now, regardless of whether an image is actually selected to be uploaded,
I get the following error:

--- start ---
Server Error in '/' Application.

Invalid character in a Base-64 string.

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.FormatException: Invalid character in a
Base-64 string.

Source Error:

An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:


[FormatException: Invalid character in a Base-64 string.]
System.Convert.FromBase64String(String s) +0
System.Web.Mvc.ByteArrayModelBinder.BindModel(ControllerContext
controllerContext, ModelBindingContext bindingContext) +125
System.Web.Mvc.DefaultModelBinder.GetPropertyValue(ControllerContext
controllerContext, ModelBindingContext bindingContext,
PropertyDescriptor propertyDescriptor, IModelBinder propertyBinder) +17
System.Web.Mvc.DefaultModelBinder.BindProperty(ControllerContext
controllerContext, ModelBindingContext bindingContext,
PropertyDescriptor propertyDescriptor) +292
System.Web.Mvc.DefaultModelBinder.BindProperties(ControllerContext
controllerContext, ModelBindingContext bindingContext) +90

System.Web.Mvc.DefaultModelBinder.BindComplexElementalModel(ControllerContext
controllerContext, ModelBindingContext bindingContext, Object model) +50
System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext
controllerContext, ModelBindingContext bindingContext) +1048
System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext
controllerContext, ModelBindingContext bindingContext) +280

System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext
controllerContext, ParameterDescriptor parameterDescriptor) +257

System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext
controllerContext, ActionDescriptor actionDescriptor) +109

System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext
controllerContext, String actionName) +314
System.Web.Mvc.Controller.ExecuteCore() +105
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +39

System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext
requestContext) +7
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +34
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21

System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult
_) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +59
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult
asyncResult) +44

System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult
result) +7

System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+8679150
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +155

Version Information: Microsoft .NET Framework Version:2.0.50727.4927;
ASP.NET Version:2.0.50727.4927
--- end ---

The action method that handles the form is as follows

public ActionResult Edit(Product product, HttpPostedFileBase image) {

}

And the code inside it doesn’t actually touch the “image” yet, so I
don’t think it’s anything I’m doing in the method itself.

Any idea what’s going on here? The second I remove the enctype attribute
everything works fine again, although obviously the image doesn’t get
uploaded.

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top