Click here to Skip to main content
15,923,789 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Controller:
public ActionResult Create()
      {

          var model = new Tickets();
          PopulateLists(model);


          return View("Create");
      }

      // POST: Tickets/Create
      [HttpPost]
      public ActionResult Create(Tickets model, HttpPostedFileBase files)
      {
          if (files != null && files.ContentLength > 0)
          {
              model.File1 = new byte[files.ContentLength];
              files.InputStream.Read(model.File1, 0, files.ContentLength);
              model.File2 = new byte[files.ContentLength];
              files.InputStream.Read(model.File2, 0, files.ContentLength);
              model.File3 = new byte[files.ContentLength];
              files.InputStream.Read(model.File3, 0, files.ContentLength);
          }
          if (ModelState.IsValid)
          {

              PopulateLists(model);
              _db.Tickets.Add(model);
              _db.SaveChanges();
              // TODO: Add insert logic here
              return RedirectToAction("Tickets");
          }

          return View("Tickets");
      }

Model:
//omitted above code, not related to this section of code everything above here works fine.
public byte[] File1 { get; set; }
public byte[] File2 { get; set; }
public byte[] File3 { get; set; }


View:
//omitted not related to this section of code, everything above here works fine,

<div class="form-group">
           
            <div class="col-md-offset-2 col-md-10">
                <input type="file" id="File1" name="File1"/>
            </div>
           
            <div class="col-md-offset-2 col-md-10">
                <input type="file" id="File2" name="File2" />
            </div>
            
            <div class="col-md-offset-2 col-md-10">
                <input type="file" id="File3" name="File3" />
                <h3 />
            </div>
        </div>


Just now getting to the point in my project that I want to upload files, I have a pretty good idea of how I am going to add it to the project, however what fields would I use in database table to (I should say type of fields) If Or do you recommend something else?

Keep in mind I am using C#6, MVC5/6 Razor sql database and asp.net with entity framework, anything else you need to know ask, but ask clearly because I can still misunderstand since I am a newbie. Thank you all for your suggestions in advance!

What I have tried:

still researching before implementing anything in project... I am newish (4 months self teaching)
Posted
Updated 13-Apr-17 9:42am
v9
Comments
Timothy Heckler 7-Apr-17 23:38pm    
I am getting an error:


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.
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: 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.

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: 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. ]
System.Convert.FromBase64_Decode(Char* startInputPtr, Int32 inputLength, Byte* startDestPtr, Int32 destLength) +12271509
System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength) +130
System.Convert.FromBase64String(String s) +42
System.Web.Mvc.ByteArrayModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +98
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) +382
System.Web.Mvc.DefaultModelBinder.BindProperties(ControllerContext controllerContext, ModelBindingContext bindingContext) +122
System.Web.Mvc.DefaultModelBinder.BindComplexElementalModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Object model) +55
System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +1230
System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +348
System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +338
System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +105
System.Web.Mvc.Async.<>c__DisplayClass21.<begininvokeaction>b__19(AsyncCallback asyncCallback, Object asyncState) +743
System.Web.Mvc.Async.WrappedAsyncResult`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +14
System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state) +328
System.Web.Mvc.Controller.<beginexecutecore>b__1c(AsyncCallback asyncCallback, Object asyncState, ExecuteCoreState innerState) +25
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +30
System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) +556
System.Web.Mvc.Controller.<beginexecute>b__14(AsyncCallback asyncCallback, Object callbackState, Controller controller) +18
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +20
System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
System.We
Patrice T 12-Apr-17 14:38pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.

1 solution

Quote:
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.

You code fails because you try to base64 decode a string that is not base64 encoded.
The problem is not in your code, at least not now.
You need to show the offending string to identify the encoding, then, after, change the code to handle the encoding.

As far as I can see, the code in your question is not related to base64 decoding.

[Update]
Quote:
I don't eve know where to start, I tried to follow a few examples on this website and others for base64, and I cant seem to get it to work, it keeps giving the same error.

Run your code on debugger and when you get the error, inspect the variable that is supposed to hold the base64 value and update your question with that value, this way, we can see what you try to decode.
Nota: the only code interesting is where the error occurs.
 
Share this answer
 
v3
Comments
Timothy Heckler 13-Apr-17 15:45pm    
I don't eve know where to start, I tried to follow a few examples on this website and others for base64, and I cant seem to get it to work, it keeps giving the same error.
Dave Kreskowiak 13-Apr-17 16:18pm    
Don't know where to start? Easy. When the debugger stops and shows you the line that threw the exception (you ARE running this under the debugger, correct?) hover the mouse of the variables in the line and examine the contents. Are they what is expected?
Timothy Heckler 13-Apr-17 16:39pm    
Doesn't give a line that is wrong, just throws the same code as above. So I deleted the code, and I am still doing research on what to try next.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900