问题
i want pass base 64 string image to server site then convert to image in c#
function readFile(input) {
CheckFileUpload(input.files.length)
if (input.files && input.files[0]) {
var img, inputID = 0;
for (var i = 0; i < input.files.length; i++) {
var reader = new FileReader();
reader.onload = (function (f) {
return function (e) {
//<input type="file" id="file_' + inputID + '" name="file_' + inputID + '" class="d-none" value="' + f + '" style="display:none" />';
var fileInput = $('<input/>')
.attr('type', "hidden")
.attr('name', 'file_' + inputID + '')
.attr('id', 'file_' + inputID + '')
.attr('value', e.target.result);
$('#imgZone').append(fileInput);
inputID++;
}
})(input.files[i]);
reader.readAsDataURL(input.files[i]);
}
}
C# Code
var filesRequest = Request.Form;
string file = filesRequest["file_1"];
byte[] bytes = Convert.FromBase64String(file); // Error (1) here
System.Drawing.Image image;
using (MemoryStream ms = new MemoryStream(bytes))
{
image = System.Drawing.Image.FromStream(ms);
}
Error (1) : 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. '
base 64 string
来源:https://stackoverflow.com/questions/59823517/how-to-convert-string-base-64-image-js-to-image-in-c