I am trying to enable visitors to upload images via my MVC website. The plan is for the user to upload the images and then in another action in the controller, fetch all of the images and display them.
My model has this field:
public virtual byte[] FileData{ get; set; }
And my database table has this column:
FileData varbinary
In my view I have the following:
<div class="form-group">
@Html.LabelFor(model => model.FileData, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.FileData, new { type = "file" })
@Html.ValidationMessageFor(model => model.FileData)
</div>
</div>
When I submit the form I get this error:
System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
My questions are:
Is the database table data type for the FileData
column correct?
Is the model type for the FileData
field correct?
What is the cause of the exception?