通过MVC2将图像保存在SQL DB中 [英] Save images in SQL DB via MVC2
本文介绍了通过MVC2将图像保存在SQL DB中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我运行我的网站时,它显示:输入不是有效的Base-64字符串,因为它包含非base 64字符,两个以上的填充字符或填充字符中的非空白字符. "
和我的查看代码:
When i run my website it show:"The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters."
And My View code:
<%@ Page Title="register" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<blog.models.users>" %>
<%@ Import Namespace="blog.Models" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%using(Html.BeginForm("register","users",FormMethod.Post,new{enctype="multipart/form-data"}))
{%> <br />
<input type="file" name="upic"/>
<input type="submit" value="upload"/>
<%}%>
</asp:Content>
控制器代码为:
the controller code is :
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult register([Bind(Exclude = "file")]HttpPostedFileBase file, users u)
{
var v = db.users;
var sna = Request.Form["name"];
if (v.Count(d => d.name == sna) > 0)
{
ckn = 0;
}
if (ckn == 1 && sna !="")
{
//如果没错误,返回首页
u.uid = SqlHelper.get_ID("users", "uid");
u.rdate = DateTime.Now;
u.ndate = DateTime.Now;
u.pwd = SqlHelper.md5(u.pwd);
u.jib = 2;
u.psum = 0;
file = Request.Files["upic"];
Int32 len = file.ContentLength;
u.pict = file.ContentType;
byte[] photo = new byte[len];
file.InputStream.Read(photo, 0, len);
u.upic = photo;
db.SubmitChanges();
db.users.InsertOnSubmit(u);
db.SubmitChanges();
}
}
那么,该错误可能会发生什么?如何解决该问题?
感谢您的帮助!
then, what may the error happen?and how to resolve this problem?
thx for helping me!
推荐答案
请阅读 ^ ].
这篇关于通过MVC2将图像保存在SQL DB中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文