Click here to Skip to main content
15,666,925 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In my MVC project, I am using viewModel that has property of type byte[]. I am using byte[] to hold image file so that this file can be passed to model. My view is strongly typed view.
The problem is whenever I click on submit button to send control to controller, I am getting exception "
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.

How can I handle this exception.
Thanks in advance.

What I have tried:

Tried converting byte[] type to null in setter but stackoverflow happened.
Updated 22-Feb-19 0:54am
Richard MacCutchan 22-Feb-19 6:39am    
Look at the error message and find out why your data is incorrect.
F-ES Sitecore 22-Feb-19 6:59am    
Post the relevant bits of code and view.

1 solution

Byte arrays and Base64 are not the same thing: Base 64 is a "stringified" representation of binary data, which uses a limited set of 64 printable characters (hence the name) to represent the same data in a way that can easily be transferred over text-based links such as HTML.
Byte arrays contain the binary data directly, and that means full eight bit data in an array.

If your method expects Base64 data, you cannot hand it binary image data and expect it to work, any more than I can hand you a copy "War and Peace" in the original Russian and expect you to read it!

If may be that you can use Convert.ToBase64String Method (System) | Microsoft Docs[^] to convert it, but since I have no access to your data, I can't tell from here if that will work - it will depend on the content of the byte array.
Share this answer

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