The problem seem originated from this line:

byte[] picture = Convert.FromBase64String(base64img);

If the base64img contains some header like data:image/png;base64, then Convert.FromBase64String() fails because the string is not fully formatted in Base64 format. Consider using string.Split() before converting from string parameter to remove corresponding Base64 header:

[HttpPost]
public ActionResult LoadImage(Car car, string base64img)
{
    // split the header and content, separated by comma
    var base64arr = base64img.Split(',');
    byte[] picture = Convert.FromBase64String(base64arr[1]);

    // do something with the image

    return View();
}

If the content string contains characters other than ASCII or trailing padding ones, you should remove them like this:

string base64str = base64arr[1];
string processed = base64str.Replace('_', '/').Replace('-', '+');

switch (base64str.Length % 4) 
{
    case 2: 
       processed += "=="; 
       break;
    case 3: 
       processed += "="; 
       break;
}

byte[] picture = Convert.FromBase64String(processed);

Also consider using FormData object when passing image formatted with Base64 string:

$('#modalWindow').on('click', '#send', function () {
    var file = $('#autoPicture').attr('src');

    // note: if you send other form data, use 'serializeArray()' or 'serialize()'

    var formData = new FormData();
    // append other form contents here
    formData.append("base64img", file);

    $.ajax({
        type: "POST",
        url: "/Home/LoadImage",
        data: formData,
        success: function (data) {
            alert('ะŸั€ะธะฒะตั‚');
        },
        error: function (error) {
            alert(error.responseText);
        }
    });
});

Note:

The equals sign like = or == at the end of Base64 encoded string serves as trailing padding characters and not all Base64 encoded strings ended with them. You can see the reason behind padding here.

Answer from Tetsuya Yamamoto on Stack Overflow
๐ŸŒ
Cryptii
cryptii.com โ€บ pipes โ€บ base64-to-hex
Base64 to hex: Encode and decode bytes online - cryptii
Base64 encoding schemes are used when binary data needs to be stored or transferred as textual data. Therefore 64 characters are chosen that are both members of a subset common to most encodings (ASCII), and also printable.
๐ŸŒ
Base64.Guru
base64.guru โ€บ converter โ€บ decode โ€บ file
Base64 to File | Base64 Decode | Base64 Converter | Base64
Decode Base64 to file using the free online decoder, which allows you to preview files directly in the browser, as well as download them, get the hex dump for any binary data, and get summary information about the original file. Please note that the preview is available only for textual values and known media files such as images, sounds, and videos.
Discussions

Convert base64 strings to byte array
On the page you need to load in the input type file, as well as display this image in img. And then ajax request to transfer the base64 string to the server and there translate it into an array of ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
C# Convert a Base64 -> byte[] - Stack Overflow
I have a Base64 byte[] array which is transferred from a stream which i need to convert it to a normal byte[] how to do this ? More on stackoverflow.com
๐ŸŒ stackoverflow.com
Base64 decode string to byte array
I feel like I have exhausted every resource online trying to find a routine to decode a Base64 encoded String. I need a method I can pass a String to and have it return something like an unsiged char[] or other form of byte array. Does anyone have anything? More on community.particle.io
๐ŸŒ community.particle.io
2
1
March 6, 2015
python - How to convert a Base64 file to bytes? - Stack Overflow
I am trying to pass a base64 to bytes. But I think I'm doing it wrong because I'm passing it to ascii. The file is much bigger but I didn't want to put it all. I hope you can support me. def conver... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Base64 Decode
base64decode.org
Base64 Decode and Encode - Online
Decode from Base64 format or encode into it with various advanced options. Our site has an easy to use online tool to convert your data.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Uint8Array โ€บ fromBase64
Uint8Array.fromBase64() - JavaScript - MDN Web Docs
The Uint8Array.fromBase64() static method creates a new Uint8Array object from a base64-encoded string. This method should be preferred over Window.atob() because it results in a byte array, which is easier to work with than a string containing raw bytes, unless your decoded binary data is ...
๐ŸŒ
Motobit Software
motobit.com โ€บ util โ€บ base64-decoder-encoder.asp
Base64 Online - base64 decode and encode
This online sample demonstrates functionality of a base64 property, ByteArray class and Huge asp file upload. You can convert texts using several code pages (using CharSet property) from Unicode string to byte array and then convert the binary data to a Base64 string.
Top answer
1 of 1
2

The problem seem originated from this line:

byte[] picture = Convert.FromBase64String(base64img);

If the base64img contains some header like data:image/png;base64, then Convert.FromBase64String() fails because the string is not fully formatted in Base64 format. Consider using string.Split() before converting from string parameter to remove corresponding Base64 header:

[HttpPost]
public ActionResult LoadImage(Car car, string base64img)
{
    // split the header and content, separated by comma
    var base64arr = base64img.Split(',');
    byte[] picture = Convert.FromBase64String(base64arr[1]);

    // do something with the image

    return View();
}

If the content string contains characters other than ASCII or trailing padding ones, you should remove them like this:

string base64str = base64arr[1];
string processed = base64str.Replace('_', '/').Replace('-', '+');

switch (base64str.Length % 4) 
{
    case 2: 
       processed += "=="; 
       break;
    case 3: 
       processed += "="; 
       break;
}

byte[] picture = Convert.FromBase64String(processed);

Also consider using FormData object when passing image formatted with Base64 string:

$('#modalWindow').on('click', '#send', function () {
    var file = $('#autoPicture').attr('src');

    // note: if you send other form data, use 'serializeArray()' or 'serialize()'

    var formData = new FormData();
    // append other form contents here
    formData.append("base64img", file);

    $.ajax({
        type: "POST",
        url: "/Home/LoadImage",
        data: formData,
        success: function (data) {
            alert('ะŸั€ะธะฒะตั‚');
        },
        error: function (error) {
            alert(error.responseText);
        }
    });
});

Note:

The equals sign like = or == at the end of Base64 encoded string serves as trailing padding characters and not all Base64 encoded strings ended with them. You can see the reason behind padding here.

๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ dotnet โ€บ api โ€บ system.convert.frombase64string
Convert.FromBase64String(String) Method (System) | Microsoft Learn
April 8, 2023 - using System; public class Example ... ctr * 4, 4); } // Encode the byte array using Base64 encoding String base64 = Convert.ToBase64String(bytes); Console.WriteLine("The encoded string: "); for (int ctr = 0; ctr <= base64.Length ...
Find elsewhere
๐ŸŒ
Online Tools
emn178.github.io โ€บ online-tools โ€บ base64_decode.html
Base64 Decode - Online Tools
Decode standard Base64, Base64URL, unpadded, IMAP-style, or custom-alphabet data to text or binary bytes online.
๐ŸŒ
Cryptii
cryptii.com โ€บ pipes โ€บ binary-to-base64
Binary to base64: Convert between bytes and base64 - cryptii
Base64 encoding schemes are used when binary data needs to be stored or transferred as textual data. Therefore 64 characters are chosen that are both members of a subset common to most encodings (ASCII), and also printable.
๐ŸŒ
Base64 Encode
base64encode.net
Base64 Encode - Online Tool
Encode and Decode Base64 data with this online base64 encoder.
๐ŸŒ
Online Tools
emn178.github.io โ€บ online-tools โ€บ base64_decode_file.html
Decode Base64 to File - Online Tools
Paste or load the complete Base64 text. Enter the desired output filename, including an extension when needed. Select Standard for common standard, URL-safe, unpadded, MIME-wrapped, or IMAP-style input.
๐ŸŒ
ASPSnippets
aspsnippets.com โ€บ Articles โ€บ 2087 โ€บ Convert-Base64-string-to-Byte-Array-using-C-and-VBNet
Convert Base64 string to Byte Array using C# and VB.Net [2026]
January 29, 2026 - Learn how to convert Base64 string to Byte Array using C# and VBNet Contains Examples, Screenshots and Free Tested Source Code for download.
๐ŸŒ
Base64 Encode
base64encode.org
Base64 Encode and Decode - Online
Need this tool again? Bookmark this page for instant access next time. Meet Base64 Decode and Encode, a simple online tool that does exactly what it says: decodes from Base64 encoding as well as encodes into it quickly and easily.
๐ŸŒ
Particle
community.particle.io โ€บ firmware
Base64 decode string to byte array - Firmware - Particle
March 6, 2015 - I feel like I have exhausted every resource online trying to find a routine to decode a Base64 encoded String. I need a method I can pass a String to and have it return something like an unsiged char[] or other form of โ€ฆ
๐ŸŒ
Nim Forum
forum.nim-lang.org โ€บ t โ€บ 7359
Base64-decoding binary data to byte array
January 3, 2021 - Sign up ยท Log in ยท Reset your password ยท Create account ยท Reset password ยท Create a new account
๐ŸŒ
Base64converter
base64converter.com
Base 64 Converter
This is a convienent online tool that allows you to convert to and from base64 data. You can encode and decode text, images, spreadsheets, documents - you name it..
๐ŸŒ
GitHub
gist.github.com โ€บ borismus โ€บ 1032746
Convert a base64 string into a binary Uint8 Array ยท GitHub
How to convert this recordfile:///var/mobile/Containers/Data/Application/9C0F0870-EA7F-4CD2-9C42-30A3E9862012/Library/Caches/hello.m4a into binary format. ... Thank you very much for this, after a week of pulling my hair out. This is the only solution that works for me. ... Thank you, good work ! ... Thank you man! you save my day! ... Thanks buddy, save my day! ... A note on the one-liners: While Uint8Array.from(atob(base64), (v) => v.charCodeAt(0)); really looks nice, I ran into memory issues on Chrome when converting a 200MB binary while the for-loop worked flawlessly